I have an app that has a separate (so to speak).. Clock
from the device's system clock. From that Clock, I need to create an alarm if that clock reaches a specific time. Now I am using AlarmManager
and PendingIntent
to create an alarm but it only takes the long triggerAtMillis
as argument. Is this based on the device's system clock?
As per the javadocs
of AlarmManager.setRepeating()
:
* @param triggerAtMillis time in milliseconds that the alarm should first
* go off, using the appropriate clock (depending on the alarm type).
So what does appropriate clock
means?
Although the AlarmManager
works on the device time, the time to trigger the alarm is provided by you.
So you can can calculate the difference between your custom clock and the device clock and then pass the time accordingly to the AlarmManager
.
You can try something like this
Step 1 Get the current time of device clock and your clock and subtract them to get the difference
Step 2 With the difference, you can now calculate the device time according to your clock time
Step 3 Now set the AlarmManager
according to that time which is the device time equivalent of your custom clock time.
Although this is a work-around, but this is what I could think of.
Hope this helps :)