I am trying to detect when a widget button is clicked, but none of the extra Intent is displayed in the onReceive method.
onReceive is called with every click, but none of my Intent add-ons appear.
My code is below: I only connect the switch button to the update, so I'm not sure if this is correct. None of the additional functions are displayed, but the categories are null , although I installed this.
onUpdate (context context, etc.):
RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.my_widget); Intent buttonIntent = new Intent(context, MyWidgetProviderClass.class); buttonIntent.setAction(ACTION_WIDGET_RECEIVER); buttonIntent.putExtra("BUTTON_CLICKED", "buttonClick"); buttonIntent.putExtra("BUTTON",899); PendingIntent muPendingIntent = PendingIntent.getBroadcast(context, 0, buttonIntent, PendingIntent.FLAG_CANCEL_CURRENT); buttonIntent.addCategory("buttonclick"); remoteViews.setOnClickPendingIntent(R.id.ToggleImageButton, myPendingIntent); appWidgetManager.updateAppWidget(appWidgetIds, remoteViews);
OnReceive ():
intent.getIntExtra("BUTTON",-1); ---> 1 intent.getCategories() --- > null
source share