Scheduling an alarm clock
From API Level 21, setAlarmClock
, which sets a new alarm and displays a status bar alarm icon, was introduced in the AlarmManager
class:
void setAlarmClock(AlarmClockInfo info, PendingIntent operation)
In the next example we are going to create an alarm clock that goes off tomorrow at 10:00 pm:
Intent intent = new Intent("my_clock_alarm"); Calendar calendar = Calendar.getInstance(); calendar.add(Calendar.DATE, 1); calendar.set(Calendar.HOUR_OF_DAY, 22); calendar.set(Calendar.MINUTE, 0); calendar.set(Calendar.SECOND, 0); PendingIntent broadcast = PendingIntent.getBroadcast( AlarmClockActivity.this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); // Only applies to newer versions If ( Build.VERSION.SDK_INT >= 21 ) { AlarmClockInfo alarmInfo = new AlarmClockInfo( calendar.getTimeInMillis(), // Create a Pending intent to show Alarm Details createShowDetailsPI())...