private void scheduleAlarms(Context context) {
AlarmManager alarmManager = (AlarmManager)context.getSystemService(Context.ALARM_SERVICE);
Intent intentOnAlaramReceiver = new Intent(context, OnAlarmReceiver.class);
PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, intentOnAlaramReceiver, 0);
String listOfIntervalConnection = Utils.getStringFromProperties(context, Properties.SP_LIST_OF_ENABLE_INTERVAL_CONNECTIONS, Properties.ENABLE_AFTER);
long enableAfter = DateUtils.MINUTE_IN_MILLIS * Long.parseLong(listOfIntervalConnection);
alarmManager.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + enableAfter, enableAfter, pendingIntent);
}
我尝试取消警报
AlarmManager alarmManager = (AlarmManager)context.getSystemService(Context.ALARM_SERVICE);
Intent intentOnAlaramReceiver = new Intent(context, OnAlarmReceiver.class);
PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, intentOnAlaramReceiver, 0);
alarmManager.cancel(pendingIntent);
但有时会被取消,有时仍然有效。为什么以及如何?我能做些什么?