build.setOngoing(true);
build.setAutoCancel(false);
notification.flags= Notification.FLAG_NO_CLEAR | Notification.FLAG_ONGOING_EVENT;
setOngoing 不起作用
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
/* Create or update. */
_notificationChannel = new NotificationChannel("TubeMateGo",
"Downlaod File Notification",
NotificationManager.IMPORTANCE_DEFAULT);
mNotifyManager.createNotificationChannel(_notificationChannel);
build = new NotificationCompat.Builder(getBaseContext(),_notificationChannel.getId());
build.setContentTitle("Download")
.setContentText("Download in progress")
.setSmallIcon(R.drawable.ic_launcher_foreground);
build.setOngoing(true);
build.setChannelId(_notificationChannel.getId());
build.setVisibility(Notification.VISIBILITY_PUBLIC);
build.setAutoCancel(false);
build.setContentIntent(_pedingIntent);
Notification notification = build.build();
notification.flags= Notification.FLAG_NO_CLEAR | Notification.FLAG_ONGOING_EVENT;
mNotifyManager.notify(id, notification);
}
else {
build = new NotificationCompat.Builder(getBaseContext());
build.setContentTitle("Download")
.setContentText("Download in progress")
.setSmallIcon(R.drawable.ic_launcher_foreground);
build.setOngoing(true);
build.setVisibility(Notification.VISIBILITY_PUBLIC);
Notification notification = build.build();
notification.flags=Notification.FLAG_NO_CLEAR | Notification.FLAG_ONGOING_EVENT;
mNotifyManager.notify(id, notification);
}
当我尝试从通知栏中删除通知时,它为什么被删除?
我不知道我错在哪里
public Notification.Builder setOngoing (boolean ongoing)
设置这是否是“持续”通知。持续通知 用户无法拒绝,因此您的应用程序或服务必须 请注意取消它们。它们通常用于指示 用户积极参与的后台任务(例如,玩 音乐)或以某种方式挂起并因此占用设备 (例如,文件下载、同步操作、活动网络连接)。
那为什么被用户驳回?
编辑2
这会发生在自定义操作系统中吗?喜欢Vivo
测试 - RedMI note 5 Pro - 工作正常 那么为什么 ?不与 Vivo 合作?
简而言之,这是由于碎片化和定制化造成的。 可能该手机有某种设置来配置该行为。
衡量问题的影响并向用户提供有关问题的必要反馈非常重要。除此之外,这可能是一项不可能解决的任务。
正如有一天有人说的:有些手机只是“垃圾”。不要浪费时间尝试解决所有可能的手机问题。