Je fais une notification et ce que je veux faire est, quand l'utilisateur clique sur la notification que j'ai envoyée pour l'effacer, je veux qu'une émission en attente soit exécutée. il existe une méthode appelée 'setDeleteIntent'. Selon la documentation de cette méthode, il doit démarrer un récepteur BraodCast en attente lorsque l'utilisateur efface la notification reçue.7En attente BroadCastReceiver ne commence pas à utiliser setDeleteIntnet
Je crée une classe Broadcast Receiver comme indiqué ci-dessous dans le code, et je fournis la méthode 'setDeleteIntent' avec diffusion en attente. Mais lors de l'exécution, lorsque la notification reçue a été effacée, le message Log dans 'onReceive' du BroadcastReceiver n'a pas été affiché sur la console !!
veuillez jeter un oeil au code ci-dessous, et s'il vous plaît laissez-nous savoir pourquoi le 'onReceive' du broadcastReceiver ne s'exécute jamais.
Note: le BroadCasrReceiver a été enregistrée à l'aide 'LocalBroadCastReceiver' comme indiqué dans le code ,.
Code:
String title = getString(R.string.app_name);
NotificationCompat.Builder builder = new NotificationCompat.Builder(this).setSmallIcon(R.drawable.ic_launcher);
builder.setStyle(new NotificationCompat.BigTextStyle().bigText(msg)).setContentText(msg).setContentTitle(title);
builder.setContentIntent(contentIntent).setAutoCancel(true);
//builder.setWhen(Long.valueOf(eu.man.m24wsapp.utils.gcm.TimeUtils.getNowTS()) + 5000);
builder.setLights(Color.argb(1, 0, 0, 255), 1000, 400);
builder.setOngoing(false);
builder.setAutoCancel(true);
builder.setDeleteIntent(getPendingBroadCast());
((NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE)).notify(NOTIFICATION_ID, builder.build());
....
....
....
//getPendingBroadCast method
private PendingIntent getPendingBroadCast() {
LocalBroadcastManager.getInstance(getApplicationContext()).registerReceiver(new BCRDismissNotification(),
new IntentFilter(BCRDismissNotification.ACTION_DISMISSED_NOTIFICATION));
Intent intent = new Intent(this, BCRDismissNotification.class);
//intent.setAction(BCRDismissNotification.ACTION_DISMISSED_NOTIFICATION);
return PendingIntent.getBroadcast(this, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT);
}
BroadCast Récepteur:
public class BCRDismissNotification extends BroadcastReceiver {
private final static String TAG = BCRDismissNotification.class.getSimpleName();
public final static String ACTION_DISMISSED_NOTIFICATION = "action_dismissed_notification";
@Override
public void onReceive(Context context, Intent intent) {
Log.i(TAG, "********************* BCR **************");
}
}