资 源 简 介
Android 创建备忘录的例子,可自定义备忘录内容,自定义时间和自定义提醒闹钟的类型、铃声等。相关代码:
c.setTimeInMillis(System.currentTimeMillis());//设置当前时间
c.set(Calendar.HOUR_OF_DAY, hourOfDay);//设置小时
c.set(Calendar.MINUTE, minute);//设置分钟
c.set(Calendar.SECOND, 0);//设置秒
c.set(Calendar.MILLISECOND, 0);//设置毫秒
Intent intent=new Intent(Sample6_12_Activity.this,AlarmReceiver.class);//运行AlarmReceiver类
PendingIntent pi=PendingIntent.getBroadcast(//创建PendingIntent对象
Sample6_12_Activity.this, 0, intent, 0);
AlarmManager alarm=(AlarmManager)Sample6_12_Activity.this.getSystemService(ALARM_SERVICE);
alarm.set(AlarmManager.RTC_WAKEUP, c.getTimeInMillis(), pi);//设置闹钟提醒一次
alarm.setRepeating(AlarmManager.RTC_WAKEUP, c.getTimeInMillis(), 120000, pi);//每两分钟提醒一次
String tempHour=(hourOfDay+"").length()>1?hourOfDay+"":"0"+hourOfDay;
String tempMinute=(minute+"").length()>1?minute+"":"0"+minute;