you can't instantiate a Uri from a string, need to use the parse()
factory method.
this is how i do it, works for me --
Intent intent = new Intent ();
intent.setAction ("android.intent.action.VIEW");
intent.addCategory ("android.intent.category.BROWSABLE");
intent.setData (Uri.parse ("http://www.cnn.com"));
context.startActivity (intent);
are you happy? :-)
J
>I am trying to create a widget that, when clicked on, launches the
>browser and goes to a particular URL. Unfortunately, I have had a lot
>of problems. I started with a (working) widget that, when clicked,
>opened the alarm clock. Then, using the code from another Groups post
>(http://groups.google.com/group/android-developers/msg/
>11e54b1df3a4d279), I tried to convert it to open the browser instead.
>Here is my (non-working) code:
>
>public class Widget extends AppWidgetProvider
>{
> public void onReceive(Context context, Intent intent)
> {
> String action = intent.getAction();
> if (AppWidgetManager.ACTION_APPWIDGET_UPDATE.equals(action))
> {
>
> RemoteViews views = new RemoteViews(context.getPackageName
>(), R.layout.widget);
>
> Intent i = new Intent(Intent.ACTION_VIEW).addCategory
>(Intent.CATEGORY_BROWSABLE).setComponent(new ComponentName
>("com.android.browser", "com.android.browser.BrowserActivity"));
> Uri url = new Uri("http://www.cnn.com");
> i.setData(url);
> PendingIntent pendingIntent = PendingIntent.getActivity
>(context, 0, i, 0);
> views.setOnClickPendingIntent(R.id.Widget, pendingIntent);
>
> AppWidgetManager.getInstance(context).updateAppWidget
>(intent.getIntArrayExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS),
>views);
> }
> }
>}
>
>First, I get an error when I try to create the new Uri -- "Cannot
>instantiate the type Uri." The Groups post I've been referencing uses
>ContentURI - a class that doesn't seem to exist. There is a class
>called ContentURIs, but I couldn't figure out a way for that to help
>me. The section in the dev guide on intents doesn't really say what a
>Uri is or how to create one, and if there's no constructor I'm rather
>befuddled.
>
>My goal is to just launch a web browser, but I inexplicably haven't
>found a single "Hello, Web Browser!" app anywhere. I'd be happy to
>abandon this code and start anew or to fix whatever the problem is
>with a Uri. If anybody has any advice to offer, I'll be the happiest
>girl in the world. Thanks!
>
>PS - Unless it's bad advice... then I'll be sad.
>
>(Note: This code is a modification of the excellent alarm clock widget
>tutorial at
>http://nexsoftware.net/wp/2009/07/29/tutorial-creating-a-custom-analogclock-widget/#)
>
>--
>You received this message because you are subscribed to the Google
>Groups "Android Developers" group.
>To post to this group, send email to [email protected]
>To unsubscribe from this group, send email to
>[email protected]
>For more options, visit this group at
>http://groups.google.com/group/android-developers?hl=en
--
jason.vp.engineering.particle
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en