Andriod 設定和取消鬧鐘
阿新 • • 發佈:2018-12-16
設定鬧鐘
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);