Je crée une application qui affiche une notification avec deux options "Dim" et "Full" lorsqu'un BroadcastReceiver est appelé. Chacun de ces boutons diffuse une action.
Jusqu'à présent, tout est possible à faire, non ?
Le problème est que les boutons affichés sur la notification ne répondent pas au tapotement, mais que la notification entière y répond (si je clique sur l'icône ou le texte au lieu du bouton).
J'ai cette fonction pour construire la notification :
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;
}
et il est appelé lors de la réception d'une émission :
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);
}
}
------ edit
Je viens de remarquer que la fonction suivante renvoie null... Alors, comment puis-je construire une intention en attente pour effectuer une diffusion ?
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;
}