Android Tutorial – Clickable Widgets

by @edent | # # # # # # | 1 comment | Read ~4,175 times.

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

One thought on “Android Tutorial – Clickable Widgets

  1. Hardik Patel says:

    It helped me alot…

Leave a Reply

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