简体   繁体   English

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 is not working 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 ?当我尝试从通知栏中删除通知时,它删除了为什么?

i dont know where i am going wrong我不知道我哪里错了

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 (eg, playing music) or is pending in some way and therefore occupying the device (eg, a file download, sync operation, active network connection).它们通常用于指示用户正在积极参与的后台任务(例如,播放音乐)或以某种方式挂起并因此占用设备(例如,文件下载、同步操作、活动网络连接)。

Then Why Its Dismissed By User?那为什么它被用户解雇了?

EDIT 2编辑 2

This Happens in Custom OS ?这发生在自定义操作系统中? Like Vivovivo一样

Test - RedMI note 5 Pro - working fine Then Why ?测试 - RedMI note 5 Pro - 工作正常 那为什么? Not working with Vivo ?不与 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.不要浪费时间尝试为每部可能的手机解决问题。

我也有这个问题,出现在vivo 1724 Android 8.1.0

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM