In android, how can I force the URI to be opened using a specific browser without selecting the "select browser" list?

I have several browsers on my Android device. I can use the following code to open the URI using the default browser for Android:

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 do the same with the specified browser installed on my device, such as Opera.

Thank you very much.

+4
source share
1 answer

you need to set packageName and className in the names of packages and browser activity classes.

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 name of the package and class by following these steps:

  • connect Android phone to PC
  • open Android Logcat
  • launch a browser from a mobile phone

In Android Logcat, you'll 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 } 

The class name will be displayed in the cmp attribute: 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.

+8
source

All Articles