2012-11-21 147 views
0

如何在单击按钮时从我的应用程序中打开Android Web浏览器中的URL。从应用程序在Android的Web浏览器中打开URL

我尝试这样做:

Intent myIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(strURL)); 

startActivity(myIntent); 

,但我得到异常:

,但我有一个例外:

"No activity found to handle Intent{action=android.intent.action.VIEW data =www.google.com" 
+0

了解关于WebViewClient的更多信息。 –

+0

如何从我的应用程序中打开Android Web浏览器中的URL? http://stackoverflow.com/q/2201917/1012284 –

+0

在清单文件中添加INTERNET权限 –

回答

2

你正在做它从根本上是正确的,你只需要包括完整的网址。

String strURL="http://www.google.com"; 
Intent myIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(strURL)); 
startActivity(myIntent); 

基本上,http是协议。这是计算机试图弄清楚你想如何打开它的方法。如果您希望通过SSL建立安全连接,您可能也会对https感兴趣。

0
String url = "http://www.example.com"; 
Intent i = new Intent(Intent.ACTION_VIEW); 
i.setData(Uri.parse(url)); 
startActivity(i); 
+1

如果您可以解释_如果您认为这回答了问题,那么您的答案将会好得多。 – Ben

0

关注这个For More Detail

试试这个:

String strURL = "http://www.google.com"; 
     Intent myIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(strURL)); 

     startActivity(myIntent); 

至于失踪的 “http://” 我只是做这样的事情:

if (!url.startsWith("http://") && !url.startsWith("https://")) 
    url = "http://" + url; 
1

几乎看起来像this将有助于阅读...从页面:

Uri uri = Uri.parse("http://androidbook.blogspot.com"); 
Intent launchBrowser = new Intent(Intent.ACTION_VIEW, uri); 
startActivity(launchBrowser); 

还有第二种方法,涉及WebView,但这似乎不是你的问题。希望这有助于。

相关问题