I've made an app that always worked until Android 6.0. I think it's the Doze feature that it's not allowing my Alarm to fire.
I use sharedpreferences to handle the options:
//ENABLE NIGHT MODE TIMER
int sHour = blockerTimerPreferences.getInt("sHour", 00);
int sMinute = blockerTimerPreferences.getInt("sMinute", 00);
Calendar sTime = Calendar.getInstance();
sTime.set(Calendar.HOUR_OF_DAY, sHour);
sTime.set(Calendar.MINUTE, sMinute);
Intent enableTimer = new Intent(context, CallReceiver.class);
enableTimer.putExtra("activate", true);
PendingIntent startingTimer = PendingIntent.getBroadcast(context, 11002233, enableTimer, PendingIntent.FLAG_UPDATE_CURRENT);
AlarmManager sAlarm = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
sAlarm.setRepeating(AlarmManager.RTC_WAKEUP,
sTime.getTimeInMillis(),
AlarmManager.INTERVAL_DAY, startingTimer);
Any clue of whats wrong here?
This is an app to block calls. Thank you!
EDIT: I have 3 files (more but...) like:
MainActivity (All code)
CallReceiver (Broadcast that triggers the alarm again (reboot etc))
CallReceiverService (Handles the call / phone state)
adb shell dumpsys alarm
to confirm that your alarm is scheduled. Note thatsetRepeating()
is inexact on Android 4.4+. "This is causing battery drain too" -- that seems unlikely. Code that does not run should consume no battery. – StratovisionsetRepeating()
will fire in that minute, no issue I think. – Swerve