Android Alarmmanager Not Waking Phone Up

android AlarmManager not waking phone up

I had a similar problem and the solution was to use WakeLocker. That should be done (preferably as the 1st thing in the receiver), or the device will wake up when the alarm is received, but will fall asleep again before context.startActivity(newIntent); is called.
(I have also observed behavior when that does not happen, so it seems to be a bit arbitrary)
So the easy and quick answer:
Make a new class called WakeLocker with this source code:

package mypackage.test;

import android.content.Context;
import android.os.PowerManager;

public abstract class WakeLocker {
private static PowerManager.WakeLock wakeLock;

public static void acquire(Context ctx) {
if (wakeLock != null) wakeLock.release();

PowerManager pm = (PowerManager) ctx.getSystemService(Context.POWER_SERVICE);
wakeLock = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK |
PowerManager.ACQUIRE_CAUSES_WAKEUP |
PowerManager.ON_AFTER_RELEASE, MainActivity.APP_TAG);
wakeLock.acquire();
}

public static void release() {
if (wakeLock != null) wakeLock.release(); wakeLock = null;
}
}

and in your receiver call WakeLocker.acquire(context); as the 1st thing.
Extra: it would also be neat to call WakeLocker.release(); once your alarm has done its thing.

Android AlarmManager not waking phone up (with or without WakeLock)

You're confusing what WakefulBroadcastReceiver does. It doesn't turn on the screen. It wakes up the processor. If you want to turn on the screen, you need to use a normal broadcast reciever and take a full wakelock- the wakelock that WakefulBroadcastReceiver takes is a partial one.

AlarmManager doesn't wake up the phone sometimes (XPERIA)

http://commonsware.com/blog/2013/03/08/warning-xperia-z-stamina-alarmmanager.html

I have Xperia L and checked this link... Well... My Xperia has Stamina mode. It seems that Stamina blocked SOMETIMES my wake up function.

To solve this you need to go to power managment options, go to stamina mode and turn it off or set our application as exception. Works fine so far, I will test more and tell if there was a problem!

Edit 1:

10:04 - I set the alarm to be fired at 10:21, checked the effect at 10:28, works!

Logs:

01-15 10:21:16.804: D/AlarmWakefulReceiver(11202): onReceive()
01-15 10:21:16.814: D/AlarmWakefulReceiver(11202): Creating service
01-15 10:21:16.834: I/IntentService(11202): Completed service

AlarmManager wouldn't wake up the phone

Note: Beginning with API 19 (KITKAT) alarm delivery is inexact: the OS will shift alarms in order to minimize wakeups and battery use. There are new APIs to support applications which need strict delivery guarantees; see setWindow(int, long, long, PendingIntent) and setExact(int, long, PendingIntent). Applications whose targetSdkVersion is earlier than API 19 will continue to see the previous behavior in which all alarms are delivered exactly when requested.

From documentation

Basically, the alarm is intended not exact to minimize wakeups and battery use. You can replace set with setExact then it should work as you required.

manager.setExact(AlarmManager.RTC_WAKEUP, calendar.timeInMillis, pendingIntent);

Alarm not waking phone

If you are using a phone with Android 6.0 or more, you have to deal with the Doze mechanism. So, when the phone is in sleep state the AlarmManager will not work immediatly. The documentation says:

Standard AlarmManager alarms (including setExact() and setWindow())
are deferred to the next maintenance window.

and

If you need to set alarms that fire while in Doze, use
setAndAllowWhileIdle() or setExactAndAllowWhileIdle().

So, just try using setExactAndAllowWhileIdle() for API > 22

Documentation here

Android AlarmManager not working while phone asleep

Thanks to CommonsWare, the problem is solved ! This fail is due to doze mode (https://developer.android.com/training/monitoring-device-state/doze-standby.html)
In short, since Android 6.0, AlarmManager is impacted and cannot fire if the device is in this doze mode. But you can replace setExact by setExactAndAllowWhileIdle. There are limitations but we have to deal with. There's the link to the post where CommonsWare answered :
sendWakefulWork not always called with cwac-wakeful-1.1.0

AlarmManager not waking up a BroadcastReceiver after the specified time

You can use Handler it's easier than using Alarm Manager.
Since you are working in Service, use a Looper

Here already accepted answers will guide you:

Clearing notification after a few seconds

Using Handler inside service

I hope I could help!

Android AlarmManager RTC_WAKEUP not waking CPU

OK, problem solved. What a stupid mistake... I was using SONY XPERIA phone for debbugging. It had some strange power saving mode "STAMINA" turned on, which prevents phone from waking up by any app that don't come from SONY.

So the code is correct. The only thing that you may add is another wakelock in the onReceive method.



Related Topics



Leave a reply



Submit