AlarmManager does not start my broadcast receiver when phone is locked for example. I search and try many solutions but none works:
AlarmManager mgr = (AlarmManager)context.getSystemService(Context.ALARM_SERVICE);
Intent i = new Intent(context, OnAlarmReceiver.class);
PendingIntent pi=PendingIntent.getBroadcast(context, 0, i, 0);
mgr.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP,
SystemClock.elapsedRealtime()+60000,
PERIOD,
pi);
but OnAlarmReceiver is never fired!
I also try with WakeLock:
@Override
public void onReceive(Context context, Intent intent) {
PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "");
wl.acquire();
// code
wl.release();
}
but also not working. why?
It should be. Here is a sample project showing a similar use of
AlarmManagerthat works perfectly fine when the screen is off and the phone is locked. In my sample, the “real work” is done by aWakefulIntentService, by means of aBroadcastReceiver, so theBroadcastReceiveris definitely getting control.