微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

android – 启动浏览器意图与自定义类 – 找不到活动

我想为给定的URL专门运行认的 Android浏览器.我正在使用这段代码
Intent i = new Intent();
i.setAction("android.intent.action.VIEW"); 
i.addCategory("android.intent.category.broWSABLE");
i.setClassName("com.google.android.browser","com.android.browser.browserActivity");
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
i.setData(Uri.parse(url));
startActivity(i);

我收到的错误是:

Unable to find explicit activity class {
com.google.android.browser/com.android.browser.browserActivity}; 
have you declared this activity in your AndroidManifest.xml?

我也试图通过包过滤目的:

i.setPackage("com.google.android.browser");

而不是setClassName,但无效:

No Activity found to handle Intent { act=android.intent.action.VIEW 
cat=[android.intent.category.broWSABLE] 
dat=http://www.google.com/ flg=0x10000000 pkg=android }

我还尝试添加< uses-library android:name =“com.google.android.browser”/>到清单.

在这里遗漏了什么吗?

PS:我不喜欢使用startActivity(新的Intent(Intent.ACTION_VIEW,Uri.parse(“http://www.google.com”))),因为它将列出浏览Intent的所有选择.

解决方法

我用这个,没关系
intent.setComponent(new ComponentName("com.android.browser","com.android.browser.browserActivity"));

我想你知道什么错了.

原文地址:https://www.jb51.cc/android/311535.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐