如果应用程序已卸载,应用程序通过警报管理器设置的警报会发生什么

时间:2013-10-19 11:00:05

标签: android android-pendingintent android-alarms

我有以下代码从我的应用中设置闹钟。

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

从设置中删除应用程序后会发生什么?警报仍然存在吗?

2 个答案:

答案 0 :(得分:12)

当您卸载计划的应用程序被卸载时,您通过AlarmManager计划的事件将被删除。

答案 1 :(得分:0)

如果您希望提醒在卸载后仍然存在,则需要将它们添加到用户的Google日历(或创建日历)中

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