7

I have the below code to set up an alarm from my app.

Intent intent = new Intent("MY_ALARM_NOTIFICATION");
intent.setClass(myActivity.this, OnAlarmReceive.class);
intent.putExtra("id", id);


PendingIntent pendingIntent = PendingIntent.getBroadcast(
                myActivity.this, Integer.parseInt(id),
                intent, PendingIntent.FLAG_UPDATE_CURRENT);

Calendar timeCal = Calendar.getInstance();
timeCal.set(Calendar.HOUR_OF_DAY, hour);
timeCal.set(Calendar.MINUTE, minutes);
timeCal.set(Calendar.DAY_OF_MONTH, day);
timeCal.set(Calendar.MONTH, month - 1);
timeCal.set(Calendar.YEAR, year);

Date date = timeCal.getTime();

AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
alarmManager.set(AlarmManager.RTC_WAKEUP, timeCal.getTimeInMillis(), pendingIntent);

What happens when I remove my application from settings ? Do the alarms remain ?

tony9099
  • 4,567
  • 9
  • 44
  • 73

2 Answers2

13

The events you schedule via AlarmManager are removed when the app that scheduled them is uninstalled.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • do you know if it is the same iOS ? – tony9099 Oct 19 '13 at 11:07
  • @tony9099: I am not aware that iOS has `AlarmManager`, `PendingIntent`, etc. You would be better served asking a separate StackOverflow question, tagged with `ios` instead of `android`, to address your concern in iOS-specific terms. – CommonsWare Oct 19 '13 at 11:13
  • @CommonsWare Is it similar in the case of "app update"? Is the pending intent given to alarm manager removed? – Tejas Aug 15 '16 at 05:41
  • @Tejas: AFAIK, no. – CommonsWare Aug 15 '16 at 10:59
  • 2
    I can verify CommonsWare's answer. Application updates DO NOT remove previous pending indents given to AlarmManager. Previously scheduled repeating alarms are fired normally, after an app update. – goseib Sep 18 '16 at 14:53
  • Thank you for your answer and comments guys! This should be in google's official docs of AlarmManager – Lucas P. Apr 15 '18 at 15:15
0

If you would like the reminders to persist after uninstall, you will need to add them to the Google Calendar of the user (or create a calendar) with an intent

  Intent intent = new Intent(Intent.ACTION_INSERT)
            .setData(CalendarContract.Events.CONTENT_URI)
            .putExtra(CalendarContract.EXTRA_EVENT_BEGIN_TIME, reminderDateTime.getMillis())
            .putExtra(CalendarContract.EXTRA_EVENT_END_TIME, reminderDateTime.getMillis())
            .putExtra(CalendarContract.Events.TITLE, "TITLE"
            .putExtra(CalendarContract.Events.DESCRIPTION, eventDescription)
            .putExtra(CalendarContract.Events.HAS_ALARM, true)
            .putExtra(CalendarContract.Events.ALLOWED_REMINDERS, new int[]{CalendarContract.Reminders.METHOD_ALARM, CalendarContract.Reminders.METHOD_ALERT})
            .putExtra(CalendarContract.Events.AVAILABILITY, CalendarContract.Events.AVAILABILITY_BUSY);
d4c0d312
  • 748
  • 8
  • 24