0
私のアプリケーションでは複数の通知を追加する必要がありますが、ユーザーが新しい通知を追加したときに古い通知が削除または取り消されます。フラグを使うべきですか?あなたがお互いをキャンセルしません各PendingIntent
通知の異なるrequestCodeを指定した場合新しい通知は古いアプリケーションをキャンセルします
Calendar calendar = Calendar.getInstance();
Intent intent;
PendingIntent pendingIntent;
AlarmManager alarmManager;
long futureInMillis;
switch (type) {
case SCHEDULE_BY_DAYS:
intent = new Intent(this, NotificationReceiver.class);
intent.putExtra(NotificationReceiver.NOTIFICATION_ID, 1);
intent.putExtra(NotificationReceiver.NOTIFICATION, getNotification("WAKEP UP days !!"));
pendingIntent = PendingIntent.getBroadcast(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
alarmManager.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, calendar.getTimeInMillis(), pendingIntent);
break;
case SCHEDULE_BY_HOURS:
futureInMillis = SystemClock.elapsedRealtime() + (value * 600000);
intent = new Intent(this, NotificationReceiver.class);
intent.putExtra(NotificationReceiver.NOTIFICATION_ID, 1);
intent.putExtra(NotificationReceiver.NOTIFICATION, getNotification("WAKEP UP hours"));
pendingIntent = PendingIntent.getBroadcast(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
alarmManager.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, futureInMillis, pendingIntent);
break;
私はユニークなコードが含まれるか、理解していませんでしたか? – user3604741
はちょうど上にカウントされます。最初の通知は1を取得し、2番目の通知は2などを取得します。これは一意でなければならず、これを確実にする最も簡単な方法です。 – F43nd1r
これはどのように動作するのかを理解するためのサンプルコードを私に与えることができますか?同じIDを取り消す必要があります。 – user3604741