![](/img/trans.png)
[英]How can I force a webview app to open links in it instead of open them in the default android browser depending on the domain?
[英]In android, How can I force open a URI using a specific browser, without popping up the 'choose browser' list?
我的 android 设备上有多个浏览器。 我可以使用以下代码使用默认的 android 浏览器打开一个 URI:
String packageName = "com.android.browser";
String className = "com.android.browser.BrowserActivity";
Intent internetIntent = new Intent(Intent.ACTION_VIEW);
internetIntent.addCategory(Intent.CATEGORY_LAUNCHER);
internetIntent.setClassName(packageName, className);
startActivity(internetIntent);
我如何使用安装在我的设备上的指定浏览器来完成相同的操作,比如 Opera。
非常感谢。
您需要将 packageName 和 className 设置为浏览器活动的 package 和 class 名称。
例如,对于 Opera Mini,您需要执行以下操作:
String packageName = "com.opera.mini.android";
String className = "com.opera.mini.android.Browser";
Intent internetIntent = new Intent(Intent.ACTION_VIEW);
internetIntent.addCategory(Intent.CATEGORY_LAUNCHER);
internetIntent.setClassName(packageName, className);
startActivity(internetIntent);
对于其他浏览器,您可以通过执行以下操作找到 package 和 class 名称:
在 Android Logcat 中,您将看到如下内容:
07-22 14:06:14.662: INFO/ActivityManager(148): Starting activity: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10200000 cmp=com.opera.mini.android/.Browser }
class 名称将显示在“cmp”属性中:cmp=com.opera.mini.android/.Browser
In this case, the package name is com.opera.mini.android and the class name is com.opera.mini.android.Browser.
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.