Two Buttons with PendingIntents - Widget

I am creating a widget with two buttons. One of them updates the contents of the widget, and the second should start the action.

I have two PendingIntent for each action, but I cannot get them to work. If someone works, the other does not.

I have reviewed the code and cannot figure out what is wrong.

Any help would be greatly appreciated.

This is the code.

    RemoteViews controls = new RemoteViews(context.getPackageName(), R.layout.miwidget);

    Intent intent = new Intent("actony.com.ACTUALIZAR_WIDGET");
    intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, widgetId);


    Intent intentSettings = new Intent();  
    intentSettings.setClass(context,WidgetConfig.class);  


    PendingIntent pendingIntentUpdate = PendingIntent.getBroadcast(context, widgetId, intent, PendingIntent.FLAG_UPDATE_CURRENT);
    controls.setOnClickPendingIntent(R.id.BtnActualizar, pendingIntentUpdate);

    PendingIntent pendingIntentSettings =  PendingIntent.getActivity(context, 0, intentSettings, 0);
    controls.setOnClickPendingIntent(R.id.botonSettings, pendingIntentSettings);
+5
source share
2 answers

Try adding getActivity PendingIntent.FLAG_UPDATE_CURRENT as well ...

 PendingIntent pendingIntentSettings =  
      PendingIntent.getActivity(context, 0, intentSettings, PendingIntent.FLAG_UPDATE_CURRENT);

and if multiple widgets are possible, add widgetId there.

Make sure that both actions / translations are specified in the manifest file.

, Intent :

 Intent intent = new Intent(context,ACTUALIZAR_WIDGET.class);
 Intent intentSettings = new Intent(context,WidgetConfig.class);

, .

, .

+2
+1

All Articles