在Android中,我如何可以强制使用特定的浏览器中打开一个URI,而不弹出的“选择浏览器的名单?而不、弹出、器中、浏览器

2023-09-05 00:38:39 作者:我姓田,却走不进你的心田

我有我的Andr​​oid设备上的多个浏览器。我可以使用下面的code打开一个URI使用默认的Andr​​oid浏览器:

I have multiple browsers on my android device. I can use the following code to open a URI using the default android browser:

    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); 

我怎样才能达到同样的使用安装设备上指定的浏览器,说戏。

How can I accomplish the same using a specified browser that is installed on my device, say Opera.

非常感谢。

推荐答案

您需要设置的packageName和类名的浏览器活动的包和类名。

you need to set packageName and className to the package and class names of the browser activity.

例如,对于Opera Mini的,你需要做到以下几点:

For example, for Opera Mini, you need to do the following:

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);

有关其他浏览器,你可以通过执行查找包和类名如下:

For other browsers, you can find the package and class name by doing the following:

在android手机连接到PC 在开放的Andr​​oid的logcat 从手机启动浏览器

在Android的logcat中,你会看到这样的事情:

In Android Logcat, you will see something like this:

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 }

类的名称将在CMP属性显示出来:CMP = com.opera.mini.android / .Browser

The class name will be shown in the 'cmp' attribute: cmp=com.opera.mini.android/.Browser

在这种情况下,包名是com.opera.mini.android和类名称是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.