4

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.

Thanks very much.

Ani William
  • 43
  • 1
  • 3

1 Answers1

9

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

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:

  • connect android phone to pc
  • open Android Logcat
  • launch the browser from the mobile phone

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 }

The class name will be shown 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.

Gabriel
  • 2,054
  • 4
  • 26
  • 34
  • Hurray! Thanks. It worked with the following values on my phone: – Ani William Jul 22 '11 at 11:34
  • Hurray! Thanks. It worked with the package value as "com.opera.browser" and class name as "com.opera.Opera" on my phone. However, since it was different on your device, other devices could have different values as well. Is there any other way to force open a URL using a specified browser/ or how do I get a list of all the package/ name for a particular browser. In the latter case, I need to update my application code, whenever a new browser version is released? – Ani William Jul 22 '11 at 11:46
  • The package and class names are not different on my device; there are two versions of opera for Android: Opera Mobile and Opera Mini. I was using Opera Mini in my example. I've checked Opera Mobile as well, and the package and class names are the ones that you used. So basically I doubt that there's possible to have a different package and class name on different devices. Also, from one version to another, it is highly unlikely that the developers will change the class and package name. So, basically, I don't think that you'll have to update your app code, or at least not very often. – Gabriel Jul 22 '11 at 13:20