尝试启动PlayStore应用时出现Android Studio错误

时间:2020-05-01 11:28:24

标签: android android-studio android-intent webview

我有一个简单的Android应用程序,完全基于html,javascript等。

在其中一个页面上,我有一个评估链接,如下所示:

<a href="https://play.app.goo.gl/?link=https://play.google.com/store/apps/details?id=com.app.example">
  <img src="images/image.png"> </a>

我认为此链接不是一个坏主意,因为例如,如果我从电子邮件中打开它,它将立即启动PlayStore应用,当该应用不存在时它仍然可以工作。

在大量搜索stackoverflow之后,我仍然无法弄清为什么在尝试启动Play商店应用时出现错误“ net :: ERR_UNKNOWN_URL_SCHEME”。

我的WebView代码如下:

package com.app.example;

import android.content.Intent;
import android.net.Uri;
import android.webkit.WebView;
import android.webkit.WebViewClient;

class MyWebViewClient extends WebViewClient {

@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {

    /* YOUR HOSTNAME */
    String hostname = "example.com"; //do I even need that?

    Uri uri = Uri.parse(url);
    if (url.startsWith("file:") || uri.getHost() != null && uri.getHost().endsWith(hostname)) {
        return false;
    }
    Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
    view.getContext().startActivity(intent);
    final boolean b = true;
    return b;


}}

0 个答案:

没有答案