notification.setOngoing(true) does not work in And

2019-07-12 10:57发布

 build.setOngoing(true);
 build.setAutoCancel(false);
 notification.flags= Notification.FLAG_NO_CLEAR | Notification.FLAG_ONGOING_EVENT;

setOngoing is not working

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 (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?

EDIT 2

This Happens in Custom OS ? Like Vivo

Test - RedMI note 5 Pro - working fine Then Why ? Not working with Vivo ?

1条回答
你好瞎i
2楼-- · 2019-07-12 11:36

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.

查看更多
登录 后发表回答