JobScheduler: controlling delay from constraints being met to job being run

A job scheduler is to schedule jobs: triggering periodically, with delay or with constraints to other jobs. If you want to fire a job instantly, it doesn’t need to bee scheduled, just launch it. ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo networkInfo = cm.getActiveNetworkInfo(); if (networkInfo != null && networkInfo.isConnectedOrConnecting()) { // If there is connectivity, … 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

How to set multiple alarms using alarm manager in android

You need to use different Broadcast id’s for the pending intents. Something like this: Intent intent = new Intent(load.this, AlarmReceiver.class); final int id = (int) System.currentTimeMillis(); PendingIntent appIntent = PendingIntent.getBroadcast(this, id, intent, PendingIntent.FLAG_ONE_SHOT); Using the system time should be a unique identifier for every pending intent you fire.

Android: Get all PendingIntents set with AlarmManager

You don’t have to keep reference to it. Just define a new PendingIntent like exactly the one that you defined in creating it. For example: if I created a PendingIntent to be fired off by the AlarmManager like this: Intent alarmIntent = new Intent(getApplicationContext(), AlarmBroadcastReceiver.class); alarmIntent.setData(Uri.parse(“custom://” + alarm.ID)); alarmIntent.setAction(String.valueOf(alarm.ID)); AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE); PendingIntent … Read more

Android AlarmManager – RTC_WAKEUP vs ELAPSED_REALTIME_WAKEUP

AlarmManager.ELAPSED_REALTIME_WAKEUP type is used to trigger the alarm since boot time: alarmManager.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, 600000, pendingIntent); will actually make the alarm go off 10 min after the device boots. There is a timer that starts running when the device boots up to measure the uptime of the device and this is the type that triggers your alarm … Read more