简体   繁体   中英

How to open specific link in android webview app?

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.

Webview包含沃达丰广告 点击下载图标后

So how would i open the link directly to playstore and not in webview if it is ads? Thank in advance

  1. 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))); 
  2. 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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM