Android 调用系统浏览器 出现activitynotfoundexception 解决办法
16lz
2021-01-23
Android 调用系统浏览器 出现activitynotfoundexception 解决办法
//正常调用系统默认浏览器 Intent intent= new Intent(); intent.setAction("android.intent.action.VIEW"); Uri content_url = Uri.parse(url); intent.setData(content_url); intent.setComponent(new ComponentName("com.android.browser", "com.android.browser.BrowserActivity")); startActivity(intent); //在某些情况下你可能想要使用的浏览器而不是让用户选择了一个, //这是我如何避免由不同的软件包的名称的activitynotfoundexceptionIntent browserIntent = new Intent(Intent.ACTION_VIEW);PackageManager packageManager = this.getPackageManager();Uri uri = Uri.parse(url);browserIntent.setDataAndType(uri, "text/html");List list = packageManager.queryIntentActivities(browserIntent, 0);for (ResolveInfo resolveInfo : list) { String activityName = resolveInfo.activityInfo.name; if (activityName.contains("BrowserActivity")) { browserIntent = packageManager.getLaunchIntentForPackage(resolveInfo.activityInfo.packageName); ComponentName comp = new ComponentName(resolveInfo.activityInfo.packageName, resolveInfo.activityInfo.name); browserIntent.setAction(Intent.ACTION_VIEW); browserIntent.addCategory(Intent.CATEGORY_BROWSABLE); browserIntent.setComponent(comp); browserIntent.setData(uri); }}startActivity(browserIntent);
更多相关文章
- 一对一直播系统开发Android ProgressBar圆形进度条颜色设置
- Android 调用第三方浏览器打开
- Android编译系统(三):官方文档Android Build System
- 系统屋索引
- SystemUI9.0系统应用图标加载流程
- android 判断系统是否有Navigation Bar
- Android 系统菜单与自定义菜单
- Android开发学习笔记(十二) 获取系统可用内存