Android:在浏览器中打开一个URL

时间:2011-06-08 10:24:02

标签: android

  

可能重复:
  How can I open a URL in Android’s web browser from my application?

我一直试图找出如何创建一个意图,它将在指定的浏览器中打开指定的URL。浏览器可能并不总是默认的。 但我无法这样做。

3 个答案:

答案 0 :(得分:20)

将Intent.ACTION_VIEW常量用作Intent操作,将url用作数据。

final Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
activity.startActivity(intent);

请注意,网址必须是完整的网址(以http://或https://开头),因此请在代码中检查网址不是简短格式,例如www.google.com,如果是用户 - 定义

答案 1 :(得分:1)

试试这个:

String url = "your URL";
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
startActivity(browserIntent);

答案 2 :(得分:1)

您可以使用其中任何一个,也请阅读Link

 Intent browserIntent = new Intent("android.intent.action.VIEW", Uri.parse("http://www.google.com")); 
startActivity(browserIntent); 

String url = "http://www.example.com";
 Intent i = new Intent(Intent.ACTION_VIEW); 
i.setData(Uri.parse(url)); startActivity(i); 
相关问题