有没有办法让用户始终选择应该打开特定链接的应用程序(浏览器)?与用户尚未选择默认程序时发生的情况类似。
My code
Intent intent = new Intent(Intent.ACTION_VIEW);
forumintent.setData(Uri.parse(url));
startActivity(intent);
以下方法适用于所有隐式意图 - 不限于您有关浏览器的问题。
一般来说。当你发出隐含的意图时(比如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);
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)