2010-09-02 100 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"); 

希望那是有帮助:)