英文:
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:
<queries>
<package android:name="com.android.chrome" />
<package android:name="com.google.android.googlequicksearchbox" /></queries>
答案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?
in particular this part:
<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>
also I think you will need the internet permission to access websites so I would add this too:
<uses-permission android:name="android.permission.INTERNET" />
Hope this helps a bit!
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论