奥利奥:停止通知在滑动时被删除

Oreo: Stop notification from getting removed on swipe

我的代码:

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();

在其他手机上工作正常,但在 Vivo V7 上不工作。 第一次滑动时,通知被删除并重新出现。但是在第二次滑动时,它完全消失了。

尝试添加这个:

notification.flags |= Notification.FLAG_NO_CLEAR;

启动虚拟前景 Service ...这将在 运行 时持续显示通知。

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.

您可以尝试以下方法:

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

参考这个Ongoing notification

选项 1: 您需要按照以下方式进行操作:

builder.setOngoing(true);

选项 2:

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

选项 3:

NotificationCompat.Builder mBuilder =

                     new NotificationCompat.Builder(this)

                    .setSmallIcon(R.drawable.ic_service_launcher)

                    .setContentTitle("My title")

                    .setOngoing(true)  

                    .setContentText("Small text with details");

这是 phone 特定问题。同样的事情适用于其他 phones 但不适用于 Vivo phones。 OEM 不应偏离库存 Android.

提供的基本实施