如果没有用户取消,可以多次显示Android抬头通知吗?

时间:2017-07-17 18:25:27

标签: android notifications heads-up-notifications

我的应用目标:

minSdkVersion 21
targetSdkVersion 25

我可以用以下方式显示抬头通知:

NotificationCompat.Builder notificationBuilder = (NotificationCompat.Builder) new NotificationCompat.Builder(activity)
            .setPriority(Notification.PRIORITY_MAX)
            .setAutoCancel(true);
notificationBuilder.setVibrate(new long[0]);
((NotificationManager) activity.getSystemService(Context.NOTIFICATION_SERVICE))
            .notify(9999, notificationBuilder.build());

当应用尝试显示具有相同ID但不同消息的另一个抬头通知时,通知会更新,但不会显示为新的抬头通知。通知不会再次显示在应用顶部。

是否有可能在没有用户取消第一次通知的情况下两次显示具有相同ID的抬头通知?

1 个答案:

答案 0 :(得分:1)

我认为setOnlyAlertOnce()方法正是您所寻找的。