当Chrome应用被终止时,Google chrome在新标签页中打开URL。正在使用以下代码。如果未终止chrome应用,则会在同一标签中打开URL,否则在新标签中打开URL。
String urlString = "https://www.google.com/";
Intent intent1 = new Intent(Intent.ACTION_VIEW, Uri.parse(urlString));
intent1.putExtra(Browser.EXTRA_APPLICATION_ID, "com.android.chrome");
intent1.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent1.setPackage("com.android.chrome");
URL应该在单个选项卡中以chrome打开。
使用EXTRA_APPLICATION_ID的目的是确保为您的应用重复使用相同的浏览器选项卡。例如:
http://developer.android.com/reference/android/provider/Browser.html#
例如
Context context = widget.getContext();
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
intent.putExtra(Browser.EXTRA_APPLICATION_ID, context.getPackageName());