notification.setOngoing(true) 在 Android 8.1 中不起作用

Ash*_*nki 3 java android operating-system android-notifications android-8.0-oreo

 build.setOngoing(true);
 build.setAutoCancel(false);
 notification.flags= Notification.FLAG_NO_CLEAR | Notification.FLAG_ONGOING_EVENT;
Run Code Online (Sandbox Code Playgroud)

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);
            }
Run Code Online (Sandbox Code Playgroud)

当我尝试从通知栏中删除通知时,它删除了为什么?

我不知道我哪里出错了

根据文档

public Notification.Builder setOngoing (boolean ongoing)
Run Code Online (Sandbox Code Playgroud)

设置这是否是“正在进行的”通知。用户无法取消正在进行的通知,因此您的应用程序或服务必须注意取消它们。它们通常用于指示用户正在积极参与(例如,播放音乐)或以某种方式挂起并因此占用设备(例如,文件下载、同步操作、活动网络连接)的后台任务。

那么为什么它被用户解雇了?

编辑 2

这会发生在自定义操作系统中吗?喜欢vivo

测试 - RedMI note 5 Pro - 工作正常 那为什么?不与 Vivo 合作?

Ray*_*aga 7

简而言之,这是由于碎片化和定制化。可能该手机具有某种设置来配置该行为。正如有一天有人说:有些手机只是 - 垃圾 -。不要浪费时间尝试为每部可能的手机解决问题。