Notification學習(2)

Notification豐富的提示方式:

1、聲音提醒

·使用默認聲音

notification.defaults |= Notification.DEFAULT_SOUND;

·使用自定義聲音

notification.sound = Uri.parse(“file:///sdcard/notification/ringer.mp3”);

·注:如果定義了默認聲音,那麼自定義聲音將被覆蓋

2、振動提醒

·使用默認振動

notification.defaults |= Notification.DEFAULT_VIBRATE;

·使用自定義振動

long[] vibrate = {0,100,200,300};
notification.vibrate = vibrate;

·注:如果定義了默認振動,那麼自定義振動將被覆蓋

3、燈光閃爍提醒

·使用默認閃爍

notification.defaults |= Notification.DEFAULT_LIGHTS;

·使用自定義閃爍

notification.ledARGB = 0xff00ff00; // LED燈的顏色,綠燈
notification.ledOnMS = 300; // LED燈顯示的毫秒數,300毫秒
notification.ledOffMS = 1000; // LED燈關閉的毫秒數,1000毫秒
notification.flags |= Notification.FLAG_SHOW_LIGHTS; // 必須加上這個標誌

4、更多特性

可以通過 Notification 的相關字段或標誌(flags)爲提醒設置更多的特性。

·FLAG_AUTO_CANCEL 標誌:當提醒被用戶點擊之後會自動被取消(cancel);

·FLAG_INSISTENT 標誌:在用戶響應之前會一直重複提醒音;

·FLAG_ONGOING_EVENT 標誌:Add this to the flags field to group the notification under the “Ongoing” title in the Notifications window.

·FLAG_NO_CLEAR 標誌:當在提醒欄中點擊“清除提醒”按鈕時,該提醒將不會被清除;

·number 字段:This value indicates the current number of events represented by the notification.The appropriate number is overlaid on top of the status bar icon. If you intend to use this
field, then you must start with “1” when the Notification is first created. (If you change the value from zero to anything greater during an update, the number is not shown.)

·iconLevel 字段:This value indicates the current level of a LevelListDrawable that is used for the notification icon. You can animate the icon in the status bar by changing this value to correlate with the drawable’s defined in a LevelListDrawable.

·contentView 字段:To define your own layout for the expanded message, instantiate a RemoteViews object and pass it to the contentView field of your Notification. Pass the PendingIntent to the contentIntent field.

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章