In android, How can I force open a URI using a specific browser, without popping up the 'choose browser' list?

后端 未结 1 403
广开言路
广开言路 2020-12-19 16:20

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


        
相关标签:
1条回答
  • 2020-12-19 16:45

    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.

    0 讨论(0)
提交回复
热议问题