Reputation: 20926
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?
Upvotes: 2
Views: 2873
Reputation: 1007484
but OnAlarmReceiver is never fired!
It should be. Here is a sample project showing a similar use of AlarmManager
that works perfectly fine when the screen is off and the phone is locked. In my sample, the "real work" is done by a WakefulIntentService
, by means of a BroadcastReceiver
, so the BroadcastReceiver
is definitely getting control.
Upvotes: 1