Android:如何将我的通知放在通知区域的顶部? [英] Android: How can I put my notification on top of notification area?

查看:17
本文介绍了Android:如何将我的通知放在通知区域的顶部?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将通知放在通知区域的顶部.

I'm trying to put my notification on top of notification area.

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

A solution is to set the parameter "when" to my notification object with a future time like:

notification.when = System.currentTimeMills()*2; 

我在此使用的代码:

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;

但某些应用(如 Facebook)可以在我的当前时间上放置一个简单的通知.

but some apps (like Facebook) are able to put a simple notification with their current time over mine.

如果我刷新通知,它会保留在这些通知之下.

If I refresh my notification it remains under these ones.

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

What parameters I have to set to put my Notification to the top of the notifications area?

推荐答案

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

You should do this. Other answers seem outdated.

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

setPriority(Notification.PRIORITY_MAX) 很重要.也可以根据需要替换为以下任意一种.

setPriority(Notification.PRIORITY_MAX) is important. It can also be replaced with any of the following as per requirement.

不同的优先级信息:

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

PRIORITY_MAX -- Use for critical and urgent notifications that alert the user to a condition that is time-critical or needs to be resolved before they can continue with a particular task.

PRIORITY_HIGH --主要用于重要的通信,例如包含用户特别感兴趣的内容的消息或聊天事件.高优先级通知触发提醒通知显示.

PRIORITY_HIGH -- Use primarily for important communication, such as message or chat events with content that is particularly interesting for the user. High-priority notifications trigger the heads-up notification display.

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

PRIORITY_DEFAULT -- Use for all notifications that don't fall into any of the other priorities described here.

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

PRIORITY_LOW -- Use for notifications that you want the user to be informed about, but that are less urgent. Low-priority notifications tend to show up at the bottom of the list, which makes them a good choice for things like public or undirected social updates: The user has asked to be notified about them, but these notifications should never take precedence over urgent or direct communication.

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

PRIORITY_MIN -- Use for contextual or background information such as weather information or contextual location information. Minimum-priority notifications do not appear in the status bar. The user discovers them on expanding the notification shade.

欲了解更多详情,请查看以下链接:http://developer.android.com/design/patterns/notifications.html#correctly_set_and_manage_notification_priority

For more details check the following link: http://developer.android.com/design/patterns/notifications.html#correctly_set_and_manage_notification_priority

这篇关于Android:如何将我的通知放在通知区域的顶部?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆