Skip to content

Commit

Permalink
Alarm: set exact time for SDK versions > 19
Browse files Browse the repository at this point in the history
  • Loading branch information
deiteris committed Mar 29, 2017
1 parent 2c8cfcf commit 8364f8e
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions app/src/main/java/com/example/yink/amadeus/AlarmActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,11 @@ private void setTimeLegacy(Calendar calendar, SharedPreferences.Editor editor) {
calendar.add(Calendar.DATE, 1);
}

alarmManager.set(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), pendingIntent);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
alarmManager.setExact(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), pendingIntent);
} else {
alarmManager.set(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), pendingIntent);
}
editor.putLong("alarm_time", calendar.getTimeInMillis());
Toast.makeText(this, "Alarm has been set for " + alarmTimePicker.getCurrentHour() + " hour(s) " + alarmTimePicker.getCurrentMinute() + " minute(s)", Toast.LENGTH_SHORT).show();
}
Expand All @@ -94,7 +98,7 @@ private void setTime(Calendar calendar, SharedPreferences.Editor editor) {
calendar.add(Calendar.DATE, 1);
}

alarmManager.setAndAllowWhileIdle(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), pendingIntent);
alarmManager.setExactAndAllowWhileIdle(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), pendingIntent);
editor.putLong("alarm_time", calendar.getTimeInMillis());
Toast.makeText(this, "Alarm has been set for " + alarmTimePicker.getHour() + " hour(s) " + alarmTimePicker.getMinute() + " minute(s)", Toast.LENGTH_SHORT).show();
}
Expand Down

0 comments on commit 8364f8e

Please sign in to comment.