1. 程式人生 > >Andriod 設定和取消鬧鐘

Andriod 設定和取消鬧鐘

設定鬧鐘

Intent intent = new Intent(context, AlarmReceiver.class); PendingIntent pi = PendingIntent.getBroadcast(context, alarmClock.getAlarmId(), intent, PendingIntent.FLAG_UPDATE_CURRENT); AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); alarmManager.setExact(AlarmManager.RTC_WAKEUP, nextTime, pi);

取消鬧鐘

Intent intent = new Intent(context, AlarmReceiver.class); PendingIntent pi = PendingIntent.getBroadcast(context, alarmClockCode, intent, PendingIntent.FLAG_UPDATE_CURRENT); AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); am.cancel(pi);