-1

I have created multiple alarms using Alarm Manager. But until it notifies, I don't know whether it's successfully created or not. Is it possible to print the information(i.e. date, time, status) of alarm manager in application ?

megha
  • 301
  • 5
  • 18

3 Answers3

2

Use adb shell dumpsys alarm

this will give you a list of all the active alarms in the AlarmManager

David Wasser
  • 93,459
  • 16
  • 209
  • 274
1

Check these questions,

Get list of active PendingIntents in AlarmManager

How to check if Alarm have been set and running

Or we can do 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, pendingIntent);

for checking the above alarm is active or not we can do like this

boolean alarmUp = (PendingIntent.getBroadcast(context, 0, 
    new Intent("com.my.package.MY_UNIQUE_ACTION"), 
    PendingIntent.FLAG_NO_CREATE) != null);

if (alarmUp) {
Log.d("myTag", "Alarm is already active");
}

Flag indicating that if the described PendingIntent does not already exist, then simply return null instead of creating it

Community
  • 1
  • 1
Anandhu
  • 312
  • 2
  • 20
  • Actually, all this does is to check if a `PendingIntent` exists. This doesn't tell you anything about whether or not the Alarm has been set, and it also won't tell you when the alarm expires, – David Wasser Jan 20 '15 at 09:04
1

I think this is your solution

Calendar calendar = Calendar.getInstance();
Long preTime = calendar.getTimeInMillis();

// set alarm after 5 minute
calendar.add(Calendar.MINUTE, 5);
    Long postTime = calendar.getTimeInMillis();
    Long delay = postTime - preTime;
AlarmManager manager = (AlarmManager)     getSystemService(Context.ALARM_SERVICE);
    manager.set(AlarmManager.RTC_WAKEUP, postTime, null);
CountDownTimer timer = new CountDownTimer(delay, 1) {
@Override
        public void onTick(long millisUntilFinished) {
            final int seconds = (int) (millisUntilFinished / 1000) % 60;
            final int minutes = (int) ((millisUntilFinished / (1000 * 60)) % 60);
runOnUiThread(new Runnable() {
@Override
                public void run() {
                    text.setText("minute " + minutes + " Second " + seconds);
                }
            });
        }
@Override
        public void onFinish() {
            // TODO Auto-generated method stub
}
    };
    timer.start();

http://www.wenda.io/questions/4377820/show-left-time-until-the-alarm-start.html

QArea
  • 4,955
  • 1
  • 12
  • 22