Ashvin solanki
Ashvin solanki

Reputation: 4809

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

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 ?

Upvotes: 1

Views: 3879

Answers (1)

Raymond Arteaga
Raymond Arteaga

Reputation: 4673

In a few words, that's due to fragmentation and customization. Probably that phone has some kind of setting to configure that behavior.

It's important to measure the impact of the issue, and give the user the necessary feedback about the problem. Beyond that, it might be an impossible task to solve.

As someone said one day: Some phones are just -trash-. Don't waste your time trying to fix an issue for every possible phone.

Upvotes: 9

Related Questions