1

I've been trying to turn the result of

AlarmManager m = (AlarmManager)ctx.getSystemService(Context.ALARM_SERVICE);
String next=m.getNextAlarmClock().getTriggerTime();

Into a long variable (I want ms from epoch), the thing is (obviously) I can't convert it directly, as the variable next only contains information about the day of the week and the time of the alarm.

Do I need to add all the info that's missing on the date by hand? Or is there any method that does it?

I also tried to use

 AlarmManager m = (AlarmManager)ctx.getSystemService(Context.ALARM_SERVICE);
 long next=m.getNextAlarmClock().getTriggerTime();

but to no avail, as It gives me a nullpointer exception.

Wazowski
  • 104
  • 2
  • 11

1 Answers1

2

getTriggerTime() returns a long not Long. Refer this

AlarmManager alarmManager = (AlarmManager)ctx.getSystemService(Context.ALARM_SERVICE);
long nextAlarmTime =alarmManager.getNextAlarmClock().getTriggerTime();

Date nextAlarmDate = new Date(nextAlarmTime);
System.out.println(nextAlarmDate);

Here, the return value is the time at which the alarm is going to trigger. This value is UTC wall clock time in milliseconds.

Community
  • 1
  • 1
Uma Kanth
  • 5,659
  • 2
  • 20
  • 41
  • Thank you very much, it was a typing mistake, in my program I used long. Anyways, I tried again with your code, but it throws the following exception ``/com.example.almudena.mad_btv1 E/AndroidRuntime: FATAL EXCEPTION: main Process: com.example.almudena.mad_btv1, PID: 26198 java.lang.NullPointerException: Attempt to invoke virtual method 'long android.app.AlarmManager$AlarmClockInfo.getTriggerTime()' on a null object reference`` – Wazowski Mar 07 '16 at 09:15