Android打算在Google chrome的同一标签中打开URL

问题描述 投票:2回答:1

当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打开。

android google-chrome android-intent google-chrome-app
1个回答
0
投票

使用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());
© www.soinside.com 2019 - 2024. All rights reserved.