本文实例讲述了Android编程实现PendingIntent控制多个闹钟的方法。分享给大家供大家参考,具体如下:
要用 android.app.PendingIntent.getBroadcast(Context context, int requestCode, Intent intent)来实现控制多个闹钟,关键点在于其中的一个参数requestCode.
举例说明如下:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
|
public void setClock(){ if (lva.ids.equals( "" )||lva.ids== null ||lva.ids.length()< 0 ){ Toast.makeText(AlarmTest. this , "请选择要设定的闹钟!" , Toast.LENGTH_LONG).show(); } else { /*到这里了,重点是怎样获取时间和分钟并传入其中*/ r=dao.getAll(lva.ids.replaceAll( "[\\p{Punct}\\p{Space}]+" , "" )); Toast.makeText(AlarmTest. this , r.getId()+ "时:" +r.getHour()+ "分:" +r.getMinute(), Toast.LENGTH_LONG).show(); c.setTimeInMillis(System.currentTimeMillis()); c.set(Calendar.HOUR_OF_DAY, Integer.parseInt(r.getHour())); c.set(Calendar.MINUTE, Integer.parseInt(r.getMinute())); c.set(Calendar.SECOND, 0 ); c.set(Calendar.MILLISECOND, 0 ); Intent i= new Intent(AlarmTest. this ,CallAlarm. class ); PendingIntent sender=PendingIntent.getBroadcast(AlarmTest. this , r.getId(), i, 0 ); AlarmManager am=(AlarmManager)getSystemService(Context.ALARM_SERVICE); am.set(AlarmManager.RTC_WAKEUP, c.getTimeInMillis(), sender); } |
希望本文所述对大家Android程序设计有所帮助。