Android:如何将通知放在通知区域之上?

Mer*_*yth 21 notifications android notification-bar android-notification-bar

我正在尝试将通知放在通知区域之上.

解决方案是将参数"when"设置为我的通知对象,其未来时间如下:

notification.when = System.currentTimeMills()*2; 
Run Code Online (Sandbox Code Playgroud)

我正在使用的代码:

        long timeNotification = System.currentTimeMillis()*2;
        Notification notification = new Notification(statusIcon,c.getResources().getString(R.string.app_name),timeNotification);
        notification.flags = Notification.FLAG_ONGOING_EVENT | Notification.FLAG_NO_CLEAR;
        notification.when = timeNotification;
        notification.priority = Notification.PRIORITY_MAX;
Run Code Online (Sandbox Code Playgroud)

但是有些应用程序(比如Facebook)可以用他们当前的时间对我进行简单的通知.

如果我刷新我的通知,它仍然在这些通知之下.

我需要设置哪些参数才能将我Notification置于通知区域的顶部?

Vin*_*kar 18

你应该做这个.其他答案似乎已过时.

NotificationCompat.Builder mBuilder =
            (NotificationCompat.Builder) new NotificationCompat.Builder(context)
            .setSmallIcon(R.drawable.some_small_icon)
            .setContentTitle("Title")
            .setContentText("This is a test notification with MAX priority")
            .setPriority(Notification.PRIORITY_MAX);
Run Code Online (Sandbox Code Playgroud)

setPriority(Notification.PRIORITY_MAX)很重要.根据要求,它也可以替换为以下任何一种.

不同的优先级信息:

PRIORITY_MAX - 用于关键和紧急通知,用于提醒用户注意时间紧迫或需要在继续执行特定任务之前需要解决的情况.

PRIORITY_HIGH - 主要用于重要的通信,例如消息或聊天事件,其内容对用户特别有用.高优先级通知会触发抬头通知显示.

PRIORITY_DEFAULT - 用于不属于此处描述的任何其他优先级的所有通知.

PRIORITY_LOW - 用于通知您希望用户了解但不太紧急的通知.低优先级通知往往显示在列表的底部,这使得它们成为公共或无向社交更新等内容的良好选择:用户已要求收到有关它们的通知,但这些通知不应优先于紧急或直接沟通.

PRIORITY_MIN - 用于上下文或背景信息,例如天气信息或上下文位置信息.最低优先级通知不会出现在状态栏中.用户在扩展通知阴影时发现它们.

有关更多详细信息,请查看以下链接:http: //developer.android.com/design/patterns/notifications.html#correctly_set_and_manage_notification_priority


Hit*_*sit 4

您可以发出通知Ongoing,当它显示得比其他通常的通知更高时。但在这种情况下,用户将无法手动清除它。

为了做到这一点,请为您的Notification对象设置标志:

notif.flags = Notification.FLAG_ONGOING_EVENT | Notification.FLAG_NO_CLEAR
Run Code Online (Sandbox Code Playgroud)