Could not find any Google accoun
作者:
wenju | 来源:发表于
2023-08-28 09:59 被阅读0次public static void openUrlViaChromeBrowser(Context context, String url) {
if (TextUtils.isEmpty(url)) {
return;
}
try {
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse(url));
List<ResolveInfo> resolveInfos = null;
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M) {
resolveInfos = context.getPackageManager().queryIntentActivities(intent, PackageManager.MATCH_ALL);
}else{
resolveInfos = context.getPackageManager().queryIntentActivities(intent, 0);
}
List<String> packageNames = new ArrayList<>();
String targetPkg = "";
for (ResolveInfo resolveInfo : resolveInfos) {
String pkg = resolveInfo.activityInfo.packageName;
packageNames.add(pkg);
if (pkg.equals("com.android.chrome")){
targetPkg = pkg;
}else if (pkg.toLowerCase().contains("browser")){
targetPkg = pkg;
}
}
if (TextUtils.isEmpty(targetPkg) && !packageNames.isEmpty()){
targetPkg = packageNames.get(0);
}
intent.setPackage(targetPkg);
context.startActivity(intent);
} catch (Exception e) {
e.printStackTrace();
}
}
本文标题:Could not find any Google accoun
本文链接:https://www.haomeiwen.com/subject/iijgmdtx.html
网友评论