2010-09-02 96 views
0

我有以下代碼:如何啓動android瀏覽器?

Intent myIntent = new Intent(Intent.ACTION_VIEW, 
    ContentURI.create(arAdapter.getItem(position).getUrl())); 
    startActivity(myIntent); 

但我得到的編譯時錯誤:

ContentURI cannot be resolved. 

我怎樣才能解決這個問題?或者有沒有不同的方式來啓動Android瀏覽器?

+1

'ContentURI'從Android SDK中大約兩年前刪除。 – CommonsWare 2010-09-02 21:36:37

回答

1
activity.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url))); 

哪裏url是一樣的東西http://google.com

1

上面的代碼:

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

是正確和功能,我只是想我會提到,你也可以在視圖中嵌入瀏覽器用WebView很容易,就像這樣:

<WebView xmlns:android="http://schemas.android.com/apk/res/android" 
android:id="@+id/webview" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
/> 

WebView顯然不是eclipse中列表的可用視圖,因此您必須手動添加XML,但它既不困難也不耗時。一旦你得到了你的Web視圖設置它的URL(和其他重要屬性)正是如此:

WebView mWebView; 
mWebView = (WebView) findViewById(R.id.webview); 
mWebView.getSettings().setJavaScriptEnabled(true); 
mWebView.getSettings().setBuiltInZoomControls(true); 
mWebView.loadUrl("http://www.google.com"); 

希望那是有幫助:)