2

My Code:

mNotifyBuilder.setSmallIcon(R.drawable.ic_status_bar)
                .setContentTitle("")
                .setOngoing(true)
                .setAutoCancel(false)
                .setTicker("")
                .setColor(ContextCompat.getColor(mContext, R.color.folderlist_bg_music))
                .setChannelId(CHANNEL_ID)
                .setContent(remoteViews).build();

Working fine on other phones, but not working on Vivo V7. On first swipe the notification is removed and it reappears. But on second swipe, it dismisses completely.

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
user1517153
  • 336
  • 2
  • 10

5 Answers5

2

start a dummy foreground Service ...this will persist the notification while it's running.

A foreground service performs some operation that is noticeable to the user. For example, an audio app would use a foreground service to play an audio track. Foreground services must display a Notification. Foreground services continue running even when the user isn't interacting with the app.

Martin Zeitler
  • 1
  • 19
  • 155
  • 216
2

Option 1: You need to do the following way:

builder.setOngoing(true);

Option 2:

Notification notification = new Notification(icon, tickerText, when);
notification.flags = Notification.FLAG_ONGOING_EVENT;

Option 3:

NotificationCompat.Builder mBuilder =

                     new NotificationCompat.Builder(this)

                    .setSmallIcon(R.drawable.ic_service_launcher)

                    .setContentTitle("My title")

                    .setOngoing(true)  

                    .setContentText("Small text with details");
frogatto
  • 28,539
  • 11
  • 83
  • 129
aanshu
  • 1,602
  • 12
  • 13
  • Working fine on other phones, but not working on Vivo V7. – user1517153 Oct 29 '18 at 09:53
  • 1
    Honestly, I am very much disappointed with Vivo, their OS is actually very unpredictable. Other applications are wont to be able to do the same. You need to lock the application if you want an application to work fine. Vivo generally closes the background services of the application. You may try by installing any alarm application it will behave the same. Even the alarm will not work. :( – aanshu Oct 29 '18 at 09:56
  • The behaviour of the Vivo is very uncertain for Microsoft applications as well. Even the outlook application does not work properly. – aanshu Oct 29 '18 at 10:05
  • I would advise not to waste your time for Vivo – aanshu Oct 29 '18 at 10:05
  • Hi @user1517153 if you feel this answer is helpful to others kindly accept it as an answer, and/or if you found it helpful kindly upvote. – aanshu Oct 31 '18 at 17:49
0

Try adding this:

notification.flags |= Notification.FLAG_NO_CLEAR;
Arahasya
  • 525
  • 3
  • 14
0

You can try the following:

builder.setOngoing(true); // Can't cancel your notification (except notificationManager.cancel(); )

Refer to this Ongoing notification

frogatto
  • 28,539
  • 11
  • 83
  • 129
Anu Bhalla
  • 422
  • 4
  • 11
0

This is phone specific issue. Same thing works for other phones but not for Vivo phones. OEMs shouldn't deviate from basic implementation that has been provided by stock Android.

user1517153
  • 336
  • 2
  • 10