下面是在android内置浏览器中打开url的代码
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.facebook.com/pantherstechnik"));
startActivity(browserIntent);
现在我想显示对话框或默认对话框,其中包含当前安装在android设备上的浏览器列表。
如果您有一个浏览器应用程序,则选择器不会启动,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);
你可以触发自定义意图选择器,如
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);