是否可以清除所有通知?
btnMessageStyle1.setOnClickListener
(arg0 -> {
final int NOTIFICATION_ID = 1;
mNotifyManager =
(NotificationManager)
getSystemService(Context.NOTIFICATION_SERVICE);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
// makeNotificationChannel("CHANNEL_1", "Example
channel",
NotificationManager.IMPORTANCE_DEFAULT);
NotificationChannel channel = new
NotificationChannel("CHANNEL_1",
"Channel human readable title",
NotificationManager.IMPORTANCE_DEFAULT);
mNotifyManager.createNotificationChannel(channel);
}
build = new NotificationCompat.Builder(getApplicationContext(), "CHANNEL_1");
build.setContentTitle("Download")
.setContentText("Download in progress")
.setOngoing(true)
.setSmallIcon(R.drawable.jd)
.setLargeIcon(BitmapFactory.decodeResource(getResources(),
R.mipmap.ic_launcher))
.setAutoCancel(true)
// .setContentIntent(resultPendingIntent)
.setPriority(NotificationCompat.PRIORITY_HIGH)
.setWhen(System.currentTimeMillis());
mNotifyManager.notify(NOTIFICATION_ID, build.build());
new Download().execute();
});
}
我尝试取消所有通知:
@Override
public void onDestroy() {
mNotifyManager.cancelAll();
super.onDestroy();
}
这个问题How to clear a notification in Android解决方案不适用于我的应用程序