android 调用系统浏览器

方法一:

Intent intent = new Intent();

intent.setAction("android.intent.action.VIEW");

intent.addCategory(Intent.CATEGORY_BROWSABLE);

Uri contentUri = Uri.parse(url);

intent.setData(contentUri);

intent.setComponent(new ComponentName("com.android.browser", "com.android.browser.BrowserActivity"));

context.startActivity(intent);

注意:有的手机应用商修改了手机系统浏览器的包名(亲测三星 SM-G9250包名是com.sec.android.app.sbrowser)所以此方法会出现android.content.ActivityNotFoundException: Unable to find explicit activity class {com.android.browser/com.android.browser.BrowserActivity}; have you declared this activity in your AndroidManifest.xml?的报错信息,所以推荐方法二

 

方法二:

Intent intent = new Intent();

intent.setAction("android.intent.action.VIEW");

intent.addCategory(Intent.CATEGORY_BROWSABLE);

Uri contentUri = Uri.parse(url);

intent.setData(contentUri); 

if(hasbrowser(content,intent)){

intent.setComponent(new ComponentName("com.android.browser", "com.android.browser.BrowserActivity"));

context.startActivity(intent);

public boolean hasbrowser(Context context, Intent intent) {
    PackageManager pm = context.getPackageManager();
    List list=pm.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);

    for (ResolveInfo resolve:list) {
        if (resolve.activityInfo.packageName.contains("com.android.browser")){
           return true;
        }
    }
    return false;
}

 

 

你可能感兴趣的:(Webview)