Skip to content Skip to sidebar Skip to footer

Android: Clickable Imageview Widget

I want to make a very simple widget: It must consist from just one image view 1) on incoming sms it should change the image 2) on click it also should change the image I tried to m

Solution 1:

I found the solution.

Sorry for those of you who read the question. Too much code inside, I understand.

The problem was that UpdateService was not the real handler of the broadcast intent. Anonymous implementation of BroadcastReceiver made all the work.

So the problem was in this code (widgetProvider):

@OverridepublicvoidonUpdate(Context context, AppWidgetManager appWidgetManager,
                 int[] appWidgetIds) {
    super.onUpdate(context, appWidgetManager, appWidgetIds);
    for (inti=0; i < appWidgetIds.length; i++) {
        intappWidgetId= appWidgetIds[i];

        RemoteViewsremoteViews=newRemoteViews(context.getPackageName(), R.layout.main);
        // wrong:// Intent widgetClickIntent = new Intent(context, UpdateService.class);// widgetClickIntent.setAction(UpdateService.ACTION_ON_CLICK);// PendingIntent pendingIntentViewClick = PendingIntent.getService(context, 0, widgetClickIntent, 0);// correct:IntentwidgetClickIntent=newIntent(UpdateService.ACTION_ON_CLICK);
        PendingIntentpendingIntentViewClick= PendingIntent.getBroadcast(context, 0, widgetClickIntent, 0);
        ///////
        remoteViews.setOnClickPendingIntent(R.id.widget_imageview, pendingIntentViewClick);
        appWidgetManager.updateAppWidget(appWidgetId, remoteViews);
    }
}

Post a Comment for "Android: Clickable Imageview Widget"