如何在android中的不同浏览器中打开一个url而不是内置的浏览器

时间:2014-08-21 06:50:03

标签: android

以下是在android内置浏览器中打开网址的代码

Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.facebook.com/pantherstechnik"));
        startActivity(browserIntent);

现在我想显示对话框或默认对话框,其中包含当前安装在Android设备上的浏览器列表。愿有人指导我怎么做。

2 个答案:

答案 0 :(得分:-1)

如果您有一个浏览器应用程序,则选择器将不会启动,该URL将加载到该浏览器应用程序上。如果您有两个或更多浏览器应用程序,Android系统会启动IntentChooser显示设备上安装的所有浏览器应用程序的列表,因此用户可以选择他喜欢的浏览器来加载URL:

Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse("http://www.facebook.com/pantherstechnik"));
Intent chooser = Intent.createChooser(intent);
startActivity(chooser);

答案 1 :(得分:-1)

您可以触发自定义意图选择器,如

Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse("http://www.facebook.com/pantherstechnik"));

始终将字符串资源用于UI文本。这就像"用"

分享这张照片
String title = getResources().getText(R.string.chooser_title);

在string.xml中定义选择器标题文本以在此处使用。

创建并启动选择器

Intent chooser = Intent.createChooser(intent, title);
startActivity(chooser);
相关问题