Notification,AlarmManger,

10:00-10:40    温习Notification,Notification的用法如下:

 

01.创建NotificationManager实例

 

NotificationManager manager =(NotificationManager)

 

getSystemService(Context.NOTIFICATION_SERVICE);

02.使用通知栏构造器实例化notification对象

Notification notification = new NotificationCompat.Builder(Context);

03.设置notification的内容

notification

.setContentTitle("This is title!")

.setContentText("This is content!")

.setWhen(System.currentTimeMillis())

.setSmallIcon(R.mipmap.small_icon)

.setLargeIcon(BitmapFactory.decodeResource(getResources(), R.mipmap.large_icon));

04.发送通知请求

manager.notify(id, notification.build());

11:00-12:00    完善TimeTable_1的闹钟功能,实现取消闹钟功能,以下是几点实现取消Alarm服务的注意事项:

 

01.需要重新创建PendingIntent,取消Alarm服务是根据PendingIntent(Context, id, intent, flag)中的id和intent进行区分的,所以id和intent的内容必须一样

02.PendingIntent的flag应为FLAG_NO_CREATE,其功能是判断是否存在该PendingIntent,即有没有创建过该Alarm服务

03.需要重新创建AlarmManager

04.取消的代码为:manager.cancel(PendingIntent);

 

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值