Android:防止应用程序打开自己的链接

发布于 2025-02-04 06:56:27 字数 137 浏览 1 评论 0原文

我有一个可以打开特定网站的网络链接的应用程序。 为了促进使用情况,该应用程序还可以选择在用户的Web浏览器中打开该应用程序的当前页面。 不幸的是,如果用户在与应用程序打开链接时选择“始终”选项,则他将无法从应用程序中打开其Web浏览器中的链接。 有办法解决吗?

I have an app that can open web links to a specific website.
To facilitate usage, the app also has an option to open the current page of the app in the user's web browser.
Unfortunately, if the user chooses the "Always" option when opening a link with the app, he can no longer open the links in his web browser from the app.
Is there a way around this ?

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

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

发布评论

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

评论(1

陌路黄昏 2025-02-11 06:56:27

以下方法适用于所有隐性意图 - 不仅限于您有关浏览器的问题。

当您发出隐式意图(例如Action_View)时,主机Android设备将检查是否有一个默认应用程序可以处理意图。如果有默认应用程序,则默认情况下,Android将自动重定向到该应用程序。

但是,您可以强迫应用程序选择器以达到隐式意图。为此,您需要使用intent.CreateChooser()方法。请参阅此示例:

Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse(url)); // only used based on your example.

String title = "Select a browser";
// Create intent to show the chooser dialog
Intent chooser = Intent.createChooser(intent, title);

// Verify the original intent will resolve to at least one activity
if (intent.resolveActivity(getPackageManager()) != null) {
    startActivity(chooser);
}

The following method works for all implicit intents - not limited to your question about browsers.

When you issue an implicit intent (like ACTION_VIEW), the host Android device will check to see whether there is a default app to handle the intent. If there is a default app, then, by default, android will automatically redirect to the app.

However, you can force an app chooser for implicit intents. For this, you need to use Intent.createChooser() method. See this example:

Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse(url)); // only used based on your example.

String title = "Select a browser";
// Create intent to show the chooser dialog
Intent chooser = Intent.createChooser(intent, title);

// Verify the original intent will resolve to at least one activity
if (intent.resolveActivity(getPackageManager()) != null) {
    startActivity(chooser);
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文