尝试从另一个Android应用程序中使用URL链接打开Chrome应用程序。

huangapple go评论69阅读模式
英文:

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

问题

我正在尝试从我的Android应用程序中使用Chrome应用程序打开一个网站。然而,每次我点击链接到以下代码的按钮时都没有得到任何响应:

public void openWebsite(View view) {

    //获取URL文本
    String url = mWebsiteEditText.getText().toString();

    //解析URI并创建意图
    Uri webpage = Uri.parse(url);
    Intent intent = new Intent(Intent.ACTION_VIEW, webpage);

    //查找一个可以处理意图的活动并启动该活动。
    if (intent.resolveActivity(getPackageManager()) != null) {
        startActivity(intent);
    } else {
        Log.d("ImplicitIntents", "无法处理此操作");
    }
}

我从这里学到并遵循了这段代码: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: interaction: PackageSetting{cc102 com.example.implicitintents/10160} -> PackageSetting{bbc8e62 com.android.chrome/10129} BLOCKED

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

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

英文:

I am trying to open a website with chrome app from my android app. However, i am not getting any response each time i click the button which link to the code below:

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

i learned and follow the code from here https://codelabs.developers.google.com/codelabs/android-training-activity-with-implicit-intent/index.html?index=..%2F..android-training#3 and below is some of the message i noticed in the Logcat in android studio when i click the button to open the link:

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

2020-08-08 01:21:23.652 31691-31691/com.example.implicitintents D/ImplicitIntents: Cant handle this

The app should open chrome just as shown here: https://codelabs.developers.google.com/codelabs/android-training-activity-with-implicit-intent/index.html?index=..%2F..android-training#5

Pardon me if the question i asked is duplicated.

答案1

得分: 0

以下是翻译好的部分:

It worked for me by adding the following lines for the calling activity in the manifest:

<queries>
  <package android:name="com.android.chrome" />
  <package android:name="com.google.android.googlequicksearchbox" /></queries>
英文:

It worked for me by adding the following lines for the calling activity in the manifest:

&lt;queries&gt;
  &lt;package android:name=&quot;com.android.chrome&quot; /&gt;
  &lt;package android:name=&quot;com.google.android.googlequicksearchbox&quot; /&gt;&lt;/queries&gt;

答案2

得分: -1

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

具体来说,是这部分内容:

<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" />

希望这对你有所帮助!

英文:

I think you might be missing some things in your manifest file. Did you follow this part of the tutorial? What does yours look like?

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

in particular this part:

&lt;intent-filter&gt;
        &lt;action android:name=&quot;android.intent.action.VIEW&quot; /&gt;
        &lt;category android:name=&quot;android.intent.category.DEFAULT&quot; /&gt;
        &lt;category android:name=&quot;android.intent.category.BROWSABLE&quot; /&gt;
        &lt;data android:scheme=&quot;http&quot; 
                            android:host=&quot;developer.android.com&quot; /&gt;
    &lt;/intent-filter&gt;

also I think you will need the internet permission to access websites so I would add this too:

&lt;uses-permission android:name=&quot;android.permission.INTERNET&quot; /&gt; 

https://stackoverflow.com/questions/2378607/what-permission-do-i-need-to-access-internet-from-an-android-application

Hope this helps a bit!

huangapple
  • 本文由 发表于 2020年8月8日 02:07:58
  • 转载请务必保留本文链接:https://go.coder-hub.com/63307123.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定