繁体   English   中英

在 android 中,如何在不弹出“选择浏览器”列表的情况下强制使用特定浏览器打开 URI?

[英]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 手机连接到电脑
  • 打开 Android Logcat
  • 从手机启动浏览器

在 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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM