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

Android: How to use AlarmManager

“Some sample code” is not that easy when it comes to AlarmManager. Here is a snippet showing the setup of AlarmManager: AlarmManager mgr=(AlarmManager)context.getSystemService(Context.ALARM_SERVICE); Intent i=new Intent(context, OnAlarmReceiver.class); PendingIntent pi=PendingIntent.getBroadcast(context, 0, i, 0); mgr.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime(), PERIOD, pi); In this example, I am using setRepeating(). If you want a one-shot alarm, you would just use set(). Be … Read more

How to check if AlarmManager already has an alarm set?

Following up on the comment ron posted, here is the detailed solution. Let’s say you have registered a repeating alarm with a pending intent like this: Intent intent = new Intent(“com.my.package.MY_UNIQUE_ACTION”); PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); Calendar calendar = Calendar.getInstance(); calendar.setTimeInMillis(System.currentTimeMillis()); calendar.add(Calendar.MINUTE, 1); AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), 1000 * 60, … Read more

Alarm Manager Example

This is working code. It wakes CPU every 10 minutes until the phone turns off. Add to Manifest.xml: … <uses-permission android:name=”android.permission.WAKE_LOCK”></uses-permission> … <receiver android:process=”:remote” android:name=”.Alarm”></receiver> … Code in your class: package yourPackage; import android.app.AlarmManager; import android.app.PendingIntent; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.os.PowerManager; import android.widget.Toast; public class Alarm extends BroadcastReceiver { @Override public void … Read more