android源码浅析--notification
类概述:一个表示如何使用NotificationManager把一个持久的通知呈现给用户的类。
The Notification.Builder has been added to make it easier to construct Notifications.
添加Notification.Builder使构建Notification更容易。
静态变量:
[java]
/**
* Use all default values (where applicable).
*/
public static final int DEFAULT_ALL = ~0;
/**
* Use the default notification sound. This will ignore any given
* {@link #sound}.
*
* @see #defaults
*/
public static final int DEFAULT_SOUND = 1;
/**
* Use the default notification vibrate. This will ignore any given
* {@link #vibrate}. Using phone vibration requires the
* {@link android.Manifest.permission#VIBRATE VIBRATE} permission.
*
* @see #defaults
*/
public static final int DEFAULT_VIBRATE = 2;
/**
* Use the default notification lights. This will ignore the
* {@link #FLAG_SHOW_LIGHTS} bit, and {@link #ledARGB}, {@link #ledOffMS}, or
* {@link #ledOnMS}.
*
* @see #defaults
*/
public static final int DEFAULT_LIGHTS = 4;
定义了默认的灯、震动、声音和全部属性。震动的话需要添加android.permission.VIBRATE权限。
[java]
* Use this constant as the value for audioStreamType to request that
* the default stream type for notifications be used. Currently the
* default stream type is STREAM_RING.
*/
public static final int STREAM_DEFAULT = -1;
notification默认的音频类型。
[java]
/**
* 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通道必须设置为向前兼容性
FLAG_ONGOING_EVENT:
如果需要notification常驻状态栏,引用正在进行的活动,如一个打进的电话,需要在Flag属性中添加FLAG_ONGOING_
补充:移动开发 , Android ,