android - NotificationManager 使用清除所有通知
问题描述
是否可以清除所有通知?
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();
}
这个问题 如何在 Android解决方案中清除通知不适用于我的应用程序
解决方案
推荐阅读
- mysql - MySQL 5.6 Show Master Status 信息存储在哪里
- python - 康达激活没有效果
- angular - 使用 Angular 解析器获取异步数据
- ironpython - 即使它们不可见,我如何迭代所有过滤器?
- python-3.x - 如何审核并最小化 requirements.txt?
- javascript - 使用 jQuery 的自动可点击图片库,第一张图片淡入/淡出,但其他图片不淡入?
- azure - 使用应用程序密码获取 AD 用户列表的方法
- sql-server - 如果用户不是系统管理员,数据库部署会无意中将 SQL Broker 对象删除到数据库中
- pandas - 如何对所有其他列都相同的一列中的值进行平均?
- r - 测试哪些因素决定了建模性能