opening app links from a webview

后端 未结 1 1695
醉话见心
醉话见心 2021-01-29 06:40

I have an android app, there is an activity with a webView, it acts like a browser (it open some links I provided). Whenever I browse through my webView if there is a link that

1条回答
  •  礼貌的吻别
    2021-01-29 07:10

    This works for me and opens play store app if it is installed and else shows playstore link within the same webView.

    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) {
                Uri uri = Uri.parse(url);
                view.loadUrl("http://play.google.com/store/apps/" + uri.getHost() + "?" + uri.getQuery());
                return false;
            }
    
        }
        return false;
    }
    });
    

    0 讨论(0)
提交回复
热议问题