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); //在某些情况下你可能想要使用的浏览器而不是让用户选择了一个, //这是我如何避免由不同的软件包的名称的activitynotfoundexception Intent 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 调用系统浏览器 出现activitynotfoundexception 解决办法
最新推荐文章于 2023-02-08 23:46:46 发布