Note that there are some explanatory texts on larger screens.

plurals
  1. POJelly bean notification actions disabled
    text
    copied!<p>I'm building an app that shows a notification with two options "Dim" and "Full" when a BroadcastReceiver is called. Each of this buttons broadcasts an action.</p> <p>So far everything is possible to do, right?</p> <p>The problem is that the buttons shown on the notification do not respond to the tap but the whole notification does (if I click on the icon or text instead of the button).</p> <p>I have this function to build the notification:</p> <pre><code>private Notification buildReleaseNotification(NotificationManager nManager, Context context) { Notification.Builder builder = new Builder(context); builder.addAction(R.drawable.rate_star_big_half_holo_dark, "Dim", buildPendingIntent(context, DIM)); builder.addAction(R.drawable.rate_star_big_on_holo_dark, "Full", buildPendingIntent(context, FULL)); builder.setContentTitle("Car notification"); builder.setContentText("Freed"); builder.setSmallIcon(R.drawable.ic_launcher); builder.setOngoing(true); Notification notification = builder.build(); return notification; } </code></pre> <p>and it is called when receiving a broadcast:</p> <pre><code> public void onReceive(Context context, Intent intent) { NotificationManager nManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); Notification noty = null; noty = buildReleaseNotification(context); startService(context, RELEASE); if (noty != null) { nManager.notify(ChangeLockService.GLOBAL_TAG, ID, noty); } } </code></pre> <p>------ edit</p> <p>Just noticed that the following function returns null... So, how can I build a pending intent to perform a broadcast?</p> <pre><code>private PendingIntent buildPendingIntent(Context context, String action) { Intent i = new Intent(action); PendingIntent pi = PendingIntent.getBroadcast(context, ID, i, Intent.FLAG_RECEIVER_REPLACE_PENDING); return pi; } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload