AlarmManager does not work on Samsung devices in Lollipop

I am developing an application that uses AlarmManager to set alarms (usually around 50) that need to be fired at a specific time during the year. This is the code I've been using since 4.4 kitkat changed AlarmManager.

AlarmManager am = (AlarmManager) getSystemService(ALARM_SERVICE); long setDate = fireDate.getTime(); // it 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); } 

In addition to the code above, I use a broadcast receiver that is correctly defined in the manifest.

 public class LocalReceiver extends BroadcastReceiver { public void onReceive(Context context, Intent intent) { PushWakeLocker.acquire(context); // do some stuff PushWakeLocker.release(); } } 

Additional information may help.

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

Since a few months ago I received bad reviews only from Samsung devices (version 5.0 / 5.1 android), which do not receive their local notifications at all. I mean that it does not work when an alarm occurs, it seems that the device is skipping it or not waking up.

In tests, mostly with the Samsung S4 with 5.0.1, I always get alarms on time, so it drives me crazy. FYI this code always worked very well.

I researched a lot about this, but unfortunately I did not get any useful information. It’s not that they receive an alarm with a delay (as I read in some threads), it is that they don’t receive it at all. Thus, this is not a known issue in lollipop and alarmmanager.

I appreciate your time and any suggestion is welcome!

+6
source share
1 answer

Your problem (or nightmare) is Samsung Smart Manager . This app comes preloaded with all Samsung phones since 2015 and should deactivate unused apps. "How does he know which applications are not used?" You may ask - simply:

Every application that has not been launched by the user for 3 days is deactivated.

All other AlarmManager entries - of course - are also deleted. You can read about it in your "developer forums". Feel free to follow here or here until these threads are removed by the Staff. I have not yet seen anyone from Samsung answer this topic.

The only way to fix this is to inform your application users about the situation and show them how to use the application whitelist in Smart Manager. We needed to set up a website with step-by-step instructions showing how to do this for our users.

You might consider setting up a background service or calling AlarmManager every six hours or so - none of these hacks will work.

+10
source

All Articles