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!