【问题标题】:Trying to open chrome app with a URL link from another android app尝试使用来自另一个 android 应用程序的 URL 链接打开 chrome 应用程序
【发布时间】:2020-08-07 18:07:58
【问题描述】:

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

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 studio 的 Logcat 中注意到的一些消息:

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

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

【问题讨论】:

  • 嗨,你找到背后的原因了吗?

标签: java android android-studio android-intent android-activity


【解决方案1】:

我认为您可能在清单文件中遗漏了一些内容。您是否按照教程的这一部分进行操作?你的是什么样子的?

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?

希望这会有所帮助!

【讨论】:

  • 您好,感谢您的回复,但我认为本教程 (codelabs.developers.google.com/codelabs/…) 是关于响应意图的。虽然它是相关的,但它并没有回答我的问题。但是,我发现 chrome 应用程序在我运行时拒绝启动,然后单击按钮从模拟器中的 android 应用程序启动它,而如果 android 应用程序在手机上运行,​​它会启动 chrome 应用程序。我想我现在有点头绪了。再次感谢您的回复和建议。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-10-07
  • 1970-01-01
相关资源
最近更新 更多