美文网首页
Android 跳转外部浏览器

Android 跳转外部浏览器

作者: __素颜__ | 来源:发表于2019-05-05 15:48 被阅读0次

效果图:


image.png image.png
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());
            LogUtil.d("suyan = " + componentName.getClassName());
            context.startActivity(Intent.createChooser(intent, "请选择浏览器"));
        } else {
            GlobalMethod.showToast(context, "链接错误或无浏览器");
        }
    }

相关文章

网友评论

      本文标题:Android 跳转外部浏览器

      本文链接:https://www.haomeiwen.com/subject/ellhoqtx.html