【问题标题】:Unable to open google play store from android webview无法从 android webview 打开 google play 商店
【发布时间】:2019-09-06 10:21:23
【问题描述】:

我在 android webview 中打开一个 URL,它将用户重定向到 android webview 中的 google play 商店网页,并且 play 商店页面显示 OPEN IN PLAY STORE APP

在点击该按钮时而不是打开 Play 商店应用程序webview 正在重定向到一个未找到的网址。

现在我不知道为什么会发生这种情况,因为在 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());
  • @ManoharReddy 不,它不工作
  • 为什么不直接在Play商店stackoverflow.com/questions/11753000/…打开你的应用?
  • @ManoharReddy 我必须在webview 中打开一个网址,并且该页面包含一些按钮,例如从 google play store 下载此应用程序,因此我无法直接在 play store 上打开该应用程序
  • 我不会以 Google Play 为例。 Google Play 具有特定的意图功能,因此如果您在 Android 上导航到它,它将打开 Play 商店应用程序。尝试使用其他网址。

标签: android android-intent webview android-webview google-play-console


【解决方案1】:

您需要覆盖 shouldOverrideUrlLoading,但您还必须检查 URL,如果它以 intent:// 方案开头,则有条件地创建一个意图。我们(Android WebView 团队)写了一个sample application 正是这样做的。

【讨论】:

    【解决方案2】:

    只需将这些数据放在 webview 中:

    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;
        }
    }
    

    【讨论】:

    • 请不要破坏您的帖子。直接放代码就好了,不用图片
    猜你喜欢
    • 1970-01-01
    • 2018-06-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-07-29
    相关资源
    最近更新 更多