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.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值