What happens to the alarms set via alarm manager by an app, if the app is uninstalled

你离开我真会死。 提交于 2019-12-07 00:04:36

问题


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 ?


回答1:


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




回答2:


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);


来源:https://stackoverflow.com/questions/19465314/what-happens-to-the-alarms-set-via-alarm-manager-by-an-app-if-the-app-is-uninst

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!