I have integrated a website in an android app using WebView.
webtcet.loadUrl("http://www.myaddaa.in/");
webtcet.setWebViewClient(new MyWebviewClient());
private class MyWebviewClient extends WebViewClient {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
}
But when i try to open ads link in android app(running in my phone it has google play services) it shows could not be loaded.
So how would i open the link directly to playstore and not in webview if it is ads? Thank in advance
I don'k think it's a good idea to open market directly inside the webview. The best way is to pass the intent to play store like this
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id="+YOU_APP_ID)));
If you really need this behaviour for some reason, you have to intercept all market://
links and load them as usual browser links
webView.setWebViewClient(new WebViewClient() {
@Override public boolean shouldOverrideUrlLoading(WebView view, String url) { if (Uri.parse(url).getScheme().equals("market")) { [parse the link to get app id from url] webview.loadUrl(https://play.google.com/store/apps/details?id=[YOU_APP_ID]); } });
so just intercept this links inside your shouldOverrideUrlLoading
webView.setWebViewClient(new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
if (Uri.parse(url).getScheme().equals("market")) {
try {
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url)));
return true;
} catch (ActivityNotFoundException e) {
// open link in browser as described above
}
}
return false;
}
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.