相关疑难解决方法(0)

Android 单挑通知在几秒钟后消失

我希望通知不会在几秒钟后消失。所以我创建了这样的通知:

  NotificationCompat.Builder builder = new NotificationCompat.Builder(context);
        builder.setSmallIcon(R.drawable.cast_ic_notification_small_icon)
                .setDefaults(Notification.FLAG_ONGOING_EVENT)
                .setPriority(Notification.PRIORITY_HIGH)
                .setContentTitle(notificationDetails.getSubject())
                .setContentText(notificationDetails.getMessage())
                .setColor(context.getResources().getColor(R.color.colorPrimary))
                .setOngoing(true);
Run Code Online (Sandbox Code Playgroud)

并设置 FLAG_ONGOING_EVENT 和方法 setOngoing(true)。

但几秒钟后,通知继续消失。我希望通知仅在用户单击时消失。谢谢你。

notifications android heads-up-notifications

4
推荐指数
3
解决办法
3034
查看次数