[英]detect if a market:// link is clicked in a webview
I try to execute some code after a link is clicked in a webview. 在Web视图中单击链接后,我尝试执行一些代码。 For normal links like http:// I managed this using the shouldOverrideUrlLoading method and view.loadUrl(url); 对于像http://这样的普通链接,我使用ShouldOverrideUrlLoading方法和view.loadUrl(url);进行了管理。
But with links starting with market:// to redirect to the GooglePlay App, this doesn't work. 但是使用以market://开头的链接来重定向到GooglePlay应用,这是行不通的。 loadURL("market://") throws a URL not found error. loadURL(“ market://”)引发URL找不到错误。
How can I detect if a market:// link is clicked in a webview ? 如何检测是否在Webview中单击了market://链接?
My Code: 我的代码:
wvinfo.setWebViewClient(new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
if (url.startsWith("http")) {
view.loadUrl(url); // WORKS
return true;
} else if (url.startsWith("market:")){
<DO SOMETHING SPECIAL>
view.loadUrl(url); // DOESN'T WORK
return true;
}
}
});
You already detect if a market:// link is clicked, your code is right. 您已经检测到是否单击了market://链接,您的代码是否正确。
Your question is how to call the GooglePlay App? 您的问题是如何调用GooglePlay应用? Use Intent instead of loadUrl: 使用Intent代替loadUrl:
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse(url));
startActivity(intent);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.