无法从Android WebView打开Google Play商店

3
我正在在Android webview 中打开一个URL,该URL会将用户重定向到Android webview 中的 Google Play 商店网页,商店页面会显示在Play Store应用程序中打开按钮。

enter image description here

但是,单击该按钮时,webview 会将其重定向到无法找到的Web URL,而不是打开Play Store应用程序。

enter image description here

现在我不知道为什么会出现这种情况,因为在Google Chrome应用程序中同样的情况可以正常工作。请提供更好的解决方案。

以下是我编写的一些代码:

   mWebView.loadUrl("https://play.google.com/store/apps/details?id=in.org.npci.upiapp&hl=en") 

   mWebView.setWebViewClient(new WebViewClient() {


        @Override
        public void onPageStarted(WebView view, String url, Bitmap favicon) {
            super.onPageStarted(view, url, favicon);

        }

        public boolean shouldOverrideUrlLoading(WebView view, String urlNewString) {
            return super.shouldOverrideUrlLoading(view, urlNewString);
        }

        @Override
        public void onPageFinished(WebView view, String url) {

        }
    });

注意:我只是将此 Play Store URL 用作示例。

不确定是否有帮助,但可以尝试设置WebChromeClient mWebView.setWebChromeClient(new WebChromeClient()); - Manohar
@ManoharReddy 不,它没有起作用。 - Kapil Rajput
为什么不直接在Play商店中打开您的应用程序?https://dev59.com/iWgt5IYBdhLWcg3w3xPC - Manohar
@ManoharReddy 我需要在一个 webview 中打开一个网址,该页面包含一些按钮,如从 Google Play 商店下载此应用程序,因此我无法直接打开 Play 商店中的应用程序。 - Kapil Rajput
我不会以Google Play为例。Google Play具有特定的意图功能,因此如果您在Android上导航到它,它将打开Play Store应用程序。请尝试使用不同的URL。 - Nick Fortescue
@NickFortescue 我尝试了不同的URL,但应用商店应用程序无法通过webview打开,请您在您的端上尝试一下,如果我漏掉了什么,请指导我。 - Kapil Rajput
2个回答

1
你需要重写 shouldOverrideUrlLoading 方法,但是你还必须检查 URL 并在它以 intent:// 方案开头时有条件地创建一个 Intent。我们(Android WebView 团队)编写了一个 示例应用程序,可以精确地做到这一点。

0

只需将此数据放入Web视图中:

public boolean shouldOverrideUrlLoading(WebView view, String url) {
    if (url != null && url.startsWith("https://play.google.com/store/apps/developer?id=putyourplaystoreid")) {
        Intent i = new Intent("android.intent.action.VIEW");
        i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        i.setData(Uri.parse(url));
        startActivity(i);

        return true;
    } else {
        return false;
    }
}

请不要破坏您的帖子。直接放置代码比使用图片更好。 - Elikill58

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接