安卓Notification.Builder的使用

通知的基本用法一般步骤为:

1.调用Context的getSystemService()方法获得NotificationManager进行管理;//NotificationManager manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);

2.实例化Builder;//Builder builder = new Builder(MainActivity.this);

3.设置Builder的参数,即对通知的布局进行设定;

4.设置PendingIntent;

//Intent intent = new Intent(this, NotificationActivity.class);
PendingIntent pi = PendingIntent.getActivity(this, 0, intent,                             PendingIntent.FLAG_CANCEL_CURRENT);


5.用Builder的build()方法创建出Notification的实例;//Notification notification = builder.build();

5.调用NotificationManager的notify()让通知显示出来。//manager.notify(1, notification);


以下为百度查找的资料:


方法或参数介绍:

1.PendingIntent

PendingIntent.getBroadcast(context, requestCode, intent, flags)

PendingIntent.getActivities(context, requestCode, intents, flags)

PendingIntent.getService(context, requestCode, intent, flags)

中的flags属性参数:

 

 

FLAG_ONE_SHOT 表示返回的PendingIntent仅能执行一次,执行完后自动取消

FLAG_NO_CREATE 表示如果描述的PendingIntent不存在,并不创建相应的PendingIntent,而是返回NULL

FLAG_CANCEL_CURRENT 表示相应的PendingIntent已经存在,则取消前者,然后创建新的PendingIntent

FLAG_UPDATE_CURRENT 表示更新的PendingIntent

 

 

2.notification.flags参数介绍

 

Notification.FLAG_SHOW_LIGHTS //三色灯提醒,在使用三色灯提醒时候必须加该标志符

Notification.FLAG_ONGOING_EVENT //发起正在运行事件(活动中)

Notification.FLAG_INSISTENT //让声音、振动无限循环,直到用户响应 (取消或者打开)

Notification.FLAG_ONLY_ALERT_ONCE //发起Notification后,铃声和震动均只执行一次

Notification.FLAG_AUTO_CANCEL //用户单击通知后自动消失

Notification.FLAG_NO_CLEAR //只有全部清除时,Notification才会清除 ,不清楚该通知(QQ的通知无法清除,就是用的这个)

Notification.FLAG_FOREGROUND_SERVICE //表示正在运行的服务

 

3.setVibrate(long[] pattern)

设置震动,需要权限.

?

4.builder.setOngoing( )

设置为ture,表示它为一个正在进行的通知。简单的说,当为ture时,不可以被侧滑消失。


  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值