Android 调用第三方浏览器打开网址或下载文件

下面写到 Application里面 :


/**
     * 调用第三方浏览器打开
     * @param context
     * @param url 要浏览的资源地址
     */ 
public static void openBrowser(Context context,String url){ 
final Intent intent = new Intent(); 
intent.setAction(Intent.ACTION_VIEW); 
intent.setData(Uri.parse(url)); 
// 注意此处的判断intent.resolveActivity()可以返回显示该Intent的Activity对应的组件名 
// 官方解释 : Name of the component implementing an activity that can display the intent 
if (intent.resolveActivity(context.getPackageManager()) != null) { 
final ComponentName componentName = intent.resolveActivity(context.getPackageManager()); // 打印Log   ComponentName到底是什么 L.d("componentName = " + componentName.getClassName()); 
context.startActivity(Intent.createChooser(intent, "请选择浏览器")); 
} else { 
Toast.makeText(context.getApplicationContext(), "请下载浏览器", Toast.LENGTH_SHORT).show(); 
} 
}

下面是调用:

Application.openBrowser(AttachmentActivity.this, url);

 

    原文作者:安卓程序员—阿杰
    原文地址: https://blog.csdn.net/qq_31020171/article/details/110453990
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞