Android:被识别为可以设为“默认”的应用程序或活动

发布于 2024-12-28 18:05:21 字数 366 浏览 0 评论 0原文

当安装了多个浏览器并且未设置默认值时,我将出现选择器对话框,可以设置默认值。

应用程序(或活动)如何使自己被系统识别为网络浏览器。 如果我这样做:

Intent intent = new Intent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_BROWSABLE);
startActivity(Intent.createChooser(intent, "TEST"));

我将获得应用程序列表:浏览器(谷歌)、联系人、Gmail、电话,但不是 Opera(迷你)浏览器。因此,Opera 没有可浏览类别,但仍然被 Android 选为网络浏览器。这是如何运作的?

When installed more than one Browser and the default is not set, I will get the chooser dialog with the possibility to set the default.

How does an application (or Activity) made itself recognizable by the system as a web browser.
If I do something like this:

Intent intent = new Intent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_BROWSABLE);
startActivity(Intent.createChooser(intent, "TEST"));

I'll get a list of the apps: Browser (google), Contacts, Gmail, Phone, but not the Opera (mini) browser. So, Opera has no category Browsable but is still picked up by Android as a web browser. How does this work?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

请别遗忘我 2025-01-04 18:05:21

这是通过添加适当的 <action> 来实现的。 <意图过滤器>在您的清单文件中,以便 Android 知道您的应用程序可以执行哪些操作以及它可以响应的意图。

It's achieved by adding appropriate <action> to <intent-filter> in your manifest file, so that Android knows what actions your app can perform and intents it can respond to.

苏辞 2025-01-04 18:05:21
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse("http://www.google.com"));
startActivity(intent);

将打开浏览器选择器,包括默认复选框。数据必须是“http:”或“https:”类型。

当然,在对话框中选择一个项目将会打开浏览器并转到指定的 URL。当单击浏览器图标时,在基本家庭应用程序中实际上就是这种情况。

这不是 100% 我所希望的(100% 是打开浏览器而不访问 URL),但可以接受。

Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse("http://www.google.com"));
startActivity(intent);

will bring up the browser chooser including the default checkbox. The data needs to be something of "http:" or "https:"-type.

Selecting an item in the dialog of course will open the browser going to the specified URL. And that is actually the case when at the base Home app when clicking to the browser icon.

This is not 100% what I hoped (100% would be open a browser without going to the URL), but acceptable.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文