views:

70

answers:

2

I have the following code:

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

But I get the compile time error:

ContentURI cannot be resolved.

How can I fix this? or is there a different way to launch the android browser?

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

Where url is something like http://google.com

DroidIn.net
+1  A: 

The above code:

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

Is correct and functional, I just thought I'd mention that you can also embed a browser in your view pretty easily with a WebView, like so:

<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 apparently is not an available view from the list in eclipse so you have to add the XML manually, but it's neither difficult nor time consuming. Once you've got your web view you set its url (and other important properties) thusly:

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

Hope that was helpful :)

David Perry