notification.setOngoing(true)在Android 8.1中不起作用 [英] notification.setOngoing(true) does not work in Android 8.1
问题描述
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);
}
当我尝试从通知栏删除通知时,其删除原因为何?
When I try to remove notification from notification bar its removed why ?
我不知道我要去哪里哪里
根据文档 a>
According to Docs
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).
那为什么它会被用户拒绝?
Then Why Its Dismissed By User?
编辑2
这在自定义操作系统中发生了吗?就像 Vivo
This Happens in Custom OS ? Like Vivo
测试-RedMI note 5 Pro-运行正常 那么为什么 ?无法使用Vivo吗?
Test - RedMI note 5 Pro - working fine Then Why ? Not working with Vivo ?
推荐答案
简而言之,这是由于碎片化和自定义所致. 可能是该电话具有某种设置来配置该行为.就像某天说的:有些电话只是-垃圾箱-.不要浪费时间尝试为每部可能的手机解决问题.
In a few words, that's due to fragmentation and customization. Probably that phone has some kind of setting to configure that behavior. As someone said one day: Some phones are just -trash-. Don't waste your time trying to fix an issue for every possible phone.
这篇关于notification.setOngoing(true)在Android 8.1中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!