2010-08-10 73 views
0

想知道是否有人知道在Android中處理打開URL的最佳方式。以下是我的工作方式:在Android中打開URL的最佳方式

String tempUrl = helper.getUrl(tempString); 
      Intent i = new Intent("android.intent.action.VIEW", Uri.parse("http://"+tempUrl)); 
      startActivity(i); 

你必須開始一項新的活動才能打開一個URL嗎?

回答

3

我想你使用了正確的方式

Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse("http://"+tempUrl)); 
startActivity(i); 

其他方式將加載您的網址進入的WebView。

myWebView.loadUrl(http://"+tempUrl); 

這是一個基本的例子:

Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://stackoverflow.com/")); 
startActivity(browserIntent); 
+0

記住要添加一個try/catch如果URL不是http你可能會在這裏得到一個異常。 – nycynik 2013-07-24 18:51:35

相關問題