Android 调用第三方浏览器打开
程序员文章站
2022-06-15 12:38:03
/** * 调用第三方浏览器打开 * * @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)); /....
/** * 调用第三方浏览器打开 * * @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到底是什么 Log.d("componentName", "componentName = " + componentName.getClassName()); context.startActivity(Intent.createChooser(intent, context.getString(R.string.please_select_browser))); } else { Toast.makeText(context.getApplicationContext(), context.getString(R.string.please_download_browser), Toast.LENGTH_SHORT).show(); } } 点击链接加入群聊【编程之美】:https://jq.qq.com/?_wv=1027&k=9qYaAE3t
本文地址:https://blog.csdn.net/wan903531306/article/details/107185681
推荐阅读