通知をキャンセルしようとしています。最初の通知から15秒以内に別の通知が送信されようとしている場合、ユーザに送信を要求しました。表示される前にアンドロイドスケジュール通知をキャンセルする
グローバル変数:
この
は私のコードですpublic NotificationManager nm;
通知機能:私はそれを気づいた
final NotificationCompat.Builder b = new NotificationCompat.Builder(this);
b.setAutoCancel(true)
.setDefaults(NotificationCompat.DEFAULT_ALL)
.setSmallIcon(R.mipmap.ic_launcher)
.setLargeIcon(BitmapFactory.decodeResource(getResources(),
R.mipmap.ic_launcher))
.setContentTitle(title)
.setContentText(message);
if (nm != null) {
Log.d(TAG, "notifyThis: cancelled");
nm.cancelAll();
} else {
Log.d(TAG, "notifyThis: not cancelled");
}
nm = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE);
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
nm.notify(1, b.build());
Log.d(TAG, "notifyThis: notify");
}
}, 15000);
通知が掲載されるまではnullのままNMので、この方法のdoesn通知は作成した後で、通知を削除する方法と、通知が.notifyによって通知される前に行う必要があります。
ありがとうございました。
完全な例を示してください。クラス宣言とメソッド宣言を含める必要があります。 –
alarmManager.cancel(pendingIntent)を呼び出すことができます。もっと読む:http://stackoverflow.com/questions/30075196/how-can-i-cancel-unshown-notifications-in-android –