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)
Set whether this is an "ongoing" notification. Ongoing notifications cannot be dismissed by the user, so your application or service must take care of canceling them. They are typically used to indicate a background task that the user is actively engaged with (e.g., playing music) or is pending in some way and therefore occupying the device (e.g., a file download, sync operation, active network connection).
那为什么会被用户拒绝呢?
编辑 2
这会发生在自定义操作系统中吗?喜欢Vivo
测试 - RedMI note 5 Pro - 工作正常 那么为什么 ?不使用 Vivo?
最佳答案
简而言之,这是由于 fragment 化和定制化造成的。 可能该电话具有某种设置来配置该行为。正如某人有一天所说:有些手机只是“垃圾”。不要浪费时间尝试为每部可能的手机解决问题。
关于java - notification.setOngoing(true) 在 Android 8.1 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53043991/