Skip to content

Instantly share code, notes, and snippets.

@kibotu
Created September 2, 2019 15:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kibotu/47ccc8c619f3a2f97f7ddaec5d248f22 to your computer and use it in GitHub Desktop.
Save kibotu/47ccc8c619f3a2f97f7ddaec5d248f22 to your computer and use it in GitHub Desktop.
setAlarm
public static void setAlarm(@Nullable Context context, @NonNull String alarmIntent, @NonNull Date notificationDate, int requestCode) {
Logger.d(TAG, "[setAlarm] alarmIntent=" + alarmIntent + " notificationTimeInMillis=" + notificationDate + " notificationsIntervalInDays=" + 1 + " requestCode=" + requestCode);
if (context == null)
return;
AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
if (alarmManager == null)
return;
Intent intent = new Intent(context, AlarmReceiver.class)
.putExtra(AlarmReceiver.ALARM_INTENT, alarmIntent);
intent.setAction(AlarmReceiver.ACTION);
alarmManager.setRepeating(AlarmManager.RTC_WAKEUP,
notificationDate.getTime(),
AlarmManager.INTERVAL_DAY,
PendingIntent.getBroadcast(context,
requestCode,
intent,
PendingIntent.FLAG_UPDATE_CURRENT));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment