读书人

android源码浅析-notification

发布时间: 2013-01-27 13:56:17 作者: rapoo

android源码浅析--notification

在上一篇文章中,用到了Notification,准备好好的看下notification的源码。

类概述:

一个表示如何使用NotificationManager把一个持久的通知呈现给用户的类。

The Notification.Builder has been added to make it easier to construct Notifications.

添加Notification.Builder使构建Notification更容易。

静态变量:

    /**     * Bit to be bitwise-ored into the {@link #flags} field that should be     * set if you want the LED on for this notification.     * <ul>     * <li>To turn the LED off, pass 0 in the alpha channel for colorARGB     *      or 0 for both ledOnMS and ledOffMS.</li>     * <li>To turn the LED on, pass 1 for ledOnMS and 0 for ledOffMS.</li>     * <li>To flash the LED, pass the number of milliseconds that it should     *      be on and off to ledOnMS and ledOffMS.</li>     * </ul>     * <p>     * Since hardware varies, you are not guaranteed that any of the values     * you pass are honored exactly.  Use the system defaults (TODO) if possible     * because they will be set to values that work on any given hardware.     * <p>     * The alpha channel must be set for forward compatibility.     *      */    public static final int FLAG_SHOW_LIGHTS        = 0x00000001;    /**     * Bit to be bitwise-ored into the {@link #flags} field that should be     * set if this notification is in reference to something that is ongoing,     * like a phone call.  It should not be set if this notification is in     * reference to something that happened at a particular point in time,     * like a missed phone call.     */    public static final int FLAG_ONGOING_EVENT      = 0x00000002;    /**     * Bit to be bitwise-ored into the {@link #flags} field that if set,     * the audio will be repeated until the notification is     * cancelled or the notification window is opened.     */    public static final int FLAG_INSISTENT          = 0x00000004;    /**     * Bit to be bitwise-ored into the {@link #flags} field that should be     * set if you want the sound and/or vibration play each time the     * notification is sent, even if it has not been canceled before that.     */    public static final int FLAG_ONLY_ALERT_ONCE    = 0x00000008;    /**     * Bit to be bitwise-ored into the {@link #flags} field that should be     * set if the notification should be canceled when it is clicked by the     * user.  On tablets, the      */    public static final int FLAG_AUTO_CANCEL        = 0x00000010;    /**     * Bit to be bitwise-ored into the {@link #flags} field that should be     * set if the notification should not be canceled when the user clicks     * the Clear all button.     */    public static final int FLAG_NO_CLEAR           = 0x00000020;    /**     * Bit to be bitwise-ored into the {@link #flags} field that should be     * set if this notification represents a currently running service.  This     * will normally be set for you by {@link Service#startForeground}.     */    public static final int FLAG_FOREGROUND_SERVICE = 0x00000040;    /**     * Bit to be bitwise-ored into the {@link #flags} field that should be set if this notification     * represents a high-priority event that may be shown to the user even if notifications are     * otherwise unavailable (that is, when the status bar is hidden). This flag is ideally used     * in conjunction with {@link #fullScreenIntent}.     */    public static final int FLAG_HIGH_PRIORITY = 0x00000080;

FLAG_SHOW_LIGHTS:如果想为Notification添加LED灯提示,需要在Flag属性中添加FLAG_SHOW_LIGHT标志位。LED关闭状态下,0表示颜色或者LED灯开关LED开启状态下,1代表LED开,0代表LED关。LED闪烁状态下,ledOnMS表示灯亮时间,ledOffMS表示灯灭时间。因为硬件不一,所以不能保证在各种硬件上都能够奏效,应尽可能使用系统给定的默认值(TODO),它能够适配各种硬件。alpha通道必须设置为向前兼容性
读书人网 >Android

热点推荐