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

查看:123
本文介绍了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天全站免登陆