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);
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!