尝试使用来自另一个 android 应用的 URL link 打开 chrome 应用

Trying to open chrome app with a URL link from another android app

我正在尝试使用 android 应用中的 chrome 应用打开一个网站。但是,每次单击下面代码的 link 按钮时,我都没有得到任何响应:

public void openWebsite(View view) {

    //Get the url text
    String url = mWebsiteEditText.getText().toString();

    //Parse the URI and create the intent
    Uri webpage = Uri.parse(url);
    Intent intent = new Intent(Intent.ACTION_VIEW, webpage);

    //Find an activity to hand the intent and start that activity.
    if (intent.resolveActivity(getPackageManager()) != null) {
        startActivity(intent);
    }else{
        Log.d("ImplicitIntents","Cant handle this");
    }
}

我从这里学习并遵循代码 https://codelabs.developers.google.com/codelabs/android-training-activity-with-implicit-intent/index.html?index=..%2F..android-training#3 以下是我在 android 工作室的 Logcat 中注意到的一些消息,当我单击按钮打开 link:

2020-08-08 01:21:23.651 767-2753/system_process I/AppsFilter:交互:PackageSetting{cc102 com.example.implicitintents/10160} - > PackageSetting{bbc8e62 com.android.chrome/10129} 阻塞

2020-08-08 01:21:23.652 31691-31691/com.example.implicitintents D/ImplicitIntents:无法处理这个

应用程序应打开 chrome,如下所示:https://codelabs.developers.google.com/codelabs/android-training-activity-with-implicit-intent/index.html?index=..%2F..android-training#5

如果我问的问题重复,请原谅。

我认为您的清单文件中可能遗漏了一些内容。您是否遵循了教程的这一部分?你的长什么样?

https://codelabs.developers.google.com/codelabs/android-training-activity-with-implicit-intent/index.html?index=..%2F..android-training#6

特别是这部分:

<intent-filter>
        <action android:name="android.intent.action.VIEW" />
        <category android:name="android.intent.category.DEFAULT" />
        <category android:name="android.intent.category.BROWSABLE" />
        <data android:scheme="http" 
                            android:host="developer.android.com" />
    </intent-filter>

另外我认为您需要互联网许可才能访问网站,所以我也要添加:

<uses-permission android:name="android.permission.INTERNET" /> 

What permission do I need to access Internet from an Android application?

希望对您有所帮助!