Android Tutorial - Clickable Widgets

Another quick Android tutorial. I couldn't find an easy or correct method of launching a browser when you click on a homescreen widget. Well, here it is...

public class clickWidget extends AppWidgetProvider
public void onUpdate( Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds )
RemoteViews remoteViews =
   new RemoteViews( context.getPackageName(), R.layout.widget );
remoteViews.setImageViewResource(, drawableResourse);

ComponentName myWidget =
   new ComponentName( context, clickWidget.class );

// Create an Intent to launch Browser
Intent intent =
   new Intent(
      Intent.ACTION_VIEW, Uri.parse("")
PendingIntent pendingIntent =
   PendingIntent.getActivity(context, 0, intent, 0);

remoteViews.setOnClickPendingIntent(, pendingIntent);
appWidgetManager.updateAppWidget( myWidget, remoteViews);

I've used this as the basis of a demo widget - "MI5 Terror Threat Level". The widget displays the UK's Threat Level on your homescreen. Clicking on it takes you to the MI5 page discussing the threat level.

The threat level is determined by parsing the RSS that the security services so helpfully provide. At the moment, the widget keeps a local copy of the graphics because the RSS feed contains references to "localhost" images.

You can download the widget by scanning in this QR code.

MI5 Widget - QR Code
MI5 Widget - QR Code

Support this blog

Enjoyed this blog post? You can say thanks to the author in the following ways:

Donate to charity
Give to charity.
Buy me a birthday present
Amazon Wishlist
Get me a coffee
Donate on Ko-Fi.

One thought on “Android Tutorial - Clickable Widgets

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.