androidalarmmanagerandroid-5.0-lollipopsamsung-mobileandroid-5.1.1-lollipop

AlarmManager not working on Samsung devices in Lollipop


I develop an app that uses AlarmManager to set a bunch alarms (usually around 50) that need to be fired at a certain time during the year. This is the code I'm using since 4.4 kitkat changed the AlarmManager.

AlarmManager am = (AlarmManager) getSystemService(ALARM_SERVICE);
long setDate = fireDate.getTime(); // it's a calendar date defined above
Intent intent = new Intent(LOCAL_DISPLAY_MESSAGE_ACTION);
PendingIntent pending = PendingIntent.getBroadcast(ctx,
                            id, intent, PendingIntent.FLAG_UPDATE_CURRENT);

if (Build.VERSION.RELEASE.startsWith("6")) {
    am.setExactAndAllowWhileIdle(AlarmManager.RTC_WAKEUP, setDate, pending);
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT){
    am.setExact(AlarmManager.RTC_WAKEUP, setDate, pending);
} else {
    am.set(AlarmManager.RTC_WAKEUP, setDate, pending);
}

Apart from the code above I'm using a broadcast receiver properly defined in the manifest.

public class LocalReceiver extends BroadcastReceiver {

    public void onReceive(Context context, Intent intent) {
        PushWakeLocker.acquire(context);

        // do some stuff

        PushWakeLocker.release();
    }
}

More info thay might help.

<uses-sdk
    android:minSdkVersion="10"
    android:targetSdkVersion="19" />

Since a few months ago I've been getting bad reviews only from Samsung devices (5.0 /5.1 android version) that don't get their local notifications at all. I mean, it's not firing the alarm, it seems that the device skips it or does not wake up.

In the tests, mainly with a Samsung S4 with 5.0.1, I always get the alarms on time, so this is driving me crazy. FYI this code has always worked pretty fine.

I researched a lot about this but unfortunately I got no helpful information. It's not that they get the alarm with delay (as I've read in some threads), it's that they don't get it at all. So this is not about the known issue in lollipop and alarmmanager.

I appreciate your time and any suggestion is welcomed!


Solution

  • Your problem (or nightmare) is the Samsung Smart Manager. This app comes pre-installed with all Samsung phones since 2015 and is supposed to deactivate Apps that are unused. "How does it know which apps are not used?" You may ask - simple:

    Every app that has not been launched by the user for 3 days gets deactivated.

    All remaining AlarmManager entries - of course - also get deleted. You can read about it on their "Developer Forums". Feel free to follow here or here until these threads get deleted by the staff. I have yet to see someone from Samsung respond to the topic.

    The only way to "fix" this is to inform the Users of your app about the situation and show them how to whitelist your app in Smart Manager. We've had to setup a website with step-by-step instructions showing how to do this for our users.

    You may think about setting up a background service, or calling AlarmManager every six hours or so - none of these hacks will work.