How to set an alarm to be scheduled at an exact time after all the newest restrictions on Android?

Found a weird workaround (sample here) that seems to work for all versions, including even Android R: Have the permission SAW permission declared in the manifest: <uses-permission android:name=”android.permission.SYSTEM_ALERT_WINDOW” /> On Android R you will have to also have it granted. On before, doesn’t seem like it’s needed to be granted, just declared. Not sure why … Read more

Should I use PendingIntent.getService() or getBroadcast with AlarmManager?

One uses PendingIntent.getBroadcast() to call a broadcast receiver when the alarm goes off and inside that receiver the service to do the real work is started. it has one more step in starting service than Another approach is to use PendingIntent.getService() and call the service directly when that alarm goes off. then you should use … Read more

setExactAndAllowWhileIdle – is not exact as of developer reference

So how can I achieve an exact alarm with AlarmManager in 6.0? You are welcome to try setAlarmClock(), as AFAIK it is unaffected by Doze mode. Otherwise, AlarmManager is not a viable option for you. Even having your app on the battery optimization whitelist will not help, as AlarmManager behavior does not change based on … Read more

Android: keeping a background service alive (preventing process death)

For Android 2.0 or later you can use the startForeground() method to start your Service in the foreground. The documentation says the following: A started service can use the startForeground(int, Notification) API to put the service in a foreground state, where the system considers it to be something the user is actively aware of and … Read more

Android cannot pass intent extras though AlarmManager

UPDATE: Please see Vincent Hiribarren’s solution Old Answer… Haresh’s code is not the complete answer… I used a Bundle and I tried without Bundle but I got null’s either way when I attempting to obtain the strings from the extra’s !! The exact problem, in your code, is with the PendingIntent ! This is wrong … Read more

How to make Alarm Manager work when Android 6.0 in Doze mode?

Doze and App Standby definitely change the behavior in regards to alarms and wakelocks, but they’re definitely not the end of the world for you! Have you tried using the method setAlarmclock() instead of set()? It’s designed specifically for alarm clocks and may be able to cut through doze. There are a few adb commands … Read more

does Alarm Manager persist even after reboot?

A simple answer would be NO. But yes you can achieve this by creating a BroadCastReceiver which will start the Alarm while booting completes of the device. Use <action android:name=”android.intent.action.BOOT_COMPLETED” /> for trapping boot activity in BroadCastReceiver class. You need to add above line in AndroidManifest.xml as follows, <receiver android:name=”.AutoStartUp” android:enabled=”true” android:exported=”false” android:permission=”android.permission.RECEIVE_BOOT_COMPLETED”> <intent-filter> <action … Read more