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);