Allow all 'market://' links from inside a webview to open Google Play store

后端 未结 3 2062
无人及你
无人及你 2020-12-05 21:57

I have some links in my webview that are market:// links. When my users tap on them, it gives them a page cannot be found error.

How can I allow all links that begin

相关标签:
3条回答
  • 2020-12-05 22:41

    you can use this code like this also if its help you:

    // It will not work in android simulator as it does not have Google Play Store
    startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id="+APP_ID)));
    
    0 讨论(0)
  • 2020-12-05 22:46

    You can decide what to do by looking the scheme of the url, if Google Play Store app is installed you can open the detail page in Play Store app, else you can show Google Play web page of the application

    webView.setWebViewClient(new WebViewClient() {
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            if (Uri.parse(url).getScheme().equals("market")) {
                try {
                    Intent intent = new Intent(Intent.ACTION_VIEW);
                    intent.setData(Uri.parse(url));
                    Activity host = (Activity) view.getContext();
                    host.startActivity(intent);
                    return true;
                } catch (ActivityNotFoundException e) {
                    // Google Play app is not installed, you may want to open the app store link
                    Uri uri = Uri.parse(url);
                    view.loadUrl("http://play.google.com/store/apps/" + uri.getHost() + "?" + uri.getQuery());
                    return false;
                }
    
            }
            return false;
        }
    });
    
    0 讨论(0)
  • 2020-12-05 22:56
     if (url.startsWith("market://")||url.startsWith("vnd:youtube")||url.startsWith("tel:")||url.startsWith("mailto:"))
    {
        Intent intent = new Intent(Intent.ACTION_VIEW); 
        intent.setData(Uri.parse(url)); 
        startActivity(intent);
        return true;
     }    
    
    0 讨论(0)
提交回复
热议问题