[Q] Get time of next alarm?

1,026 views
Skip to first unread message

Jeffrey Eng

unread,
Nov 7, 2015, 5:50:51 PM11/7/15
to Tasker
Is it possible to get the time of the next alarm set?

I'm aware of the AutoAlarm plugin, and the root method that queries the alarm database.

But, I am looking to do this natively within Tasker (to package the project as a standalone APK in the future).

Is this possible?

Juergen Gruen

unread,
Nov 8, 2015, 1:04:32 AM11/8/15
to Tasker
A1 JavaFunction: contres = CONTEXT.getContextResolver();
A2 JavaFunction: %alarm = android.provider.Settings$System.getString(contres, next_alarm_formatted);
A3 Flash %alarm


Tested on my S5 mini, Android 4.4.2, root with GentleAlarm app.

Juergen.

Juergen Gruen

unread,
Nov 8, 2015, 1:13:28 AM11/8/15
to Tasker

With API Level 21 (Lollipop) or higher you can get the time in ms since epoche:

GetNextAlarm (13)
    A1: Java Function [ Return:(AlarmManager)manager Class Or Object:CONTEXT Function:getSystemService {Object} (String) Param:alarm]
    A2: Java Function [ Return:clock Class Or Object:manager Function:getNextAlarmClock
{AlarmClockInfo} ()]
    A3: Java Function [ Return:%time Class Or Object:clock Function:getTriggerTime {long} ()]

Juergen.

Juergen Gruen

unread,
Nov 8, 2015, 1:15:50 AM11/8/15
to Tasker

... tested on a Genymotion emulator, Nexus 7, running Android 5.1

Juergen Gruen

unread,
Nov 8, 2015, 1:37:43 AM11/8/15
to Tasker


A1 JavaFunction: contres = CONTEXT.getContextResolver();


should be
 A1 JavaFunction: contres = CONTEXT.getContentResolver();

Jeffrey Eng

unread,
Nov 8, 2015, 1:46:18 AM11/8/15
to Tasker
Thanks for clarifying!

So,I'm a total noob when it comes to using Java functions in Tasker. Do I paste that whole string into the "function" field?

For instance, under "Function" I type "contres = CONTEXT.getContentResolver()" and leave the "Class or Object" field blank?

Jeffrey Eng

unread,
Nov 8, 2015, 2:34:12 AM11/8/15
to Tasker
Never mind, I figured it out!

For anyone who's wondering about syntax, refer to my screenshot (how to recreate A2 from the second post):

A1 JavaFunction: contres = CONTEXT.getContextResolver();
A2 JavaFunction: %alarm = android.provider.Settings$System.getString(contres, next_alarm_formatted);
A3 Flash %alarm
screenshot.png

Jeffrey Eng

unread,
Nov 8, 2015, 4:10:43 PM11/8/15
to Tasker
Thanks for your help so far, Juergen!

I got the task to work and even shared this with a few people on the Tasker subreddit.  

According to the Android Developer Reference page, the "next_alarm_formatted" string was depreciated as of API 21.  Google suggests using getNextAlarmClock() method instead.  

Would you know how to implement this?

Thanks!

Juergen Gruen

unread,
Nov 8, 2015, 5:14:04 PM11/8/15
to Tasker
Sure, as mentioned before:

Jeffrey Eng

unread,
Nov 8, 2015, 5:57:33 PM11/8/15
to Tasker
Ahh, I seemed to have missed that (my fault!).  Thank you!

Stefan

unread,
Feb 2, 2019, 9:44:39 AM2/2/19
to Tasker
Unfortunately getNextAlarmClock() also returns the time of the next time context used in Tasker - at least in the current beta release.

Jeffrey Eng

unread,
Feb 2, 2019, 10:05:48 AM2/2/19
to tas...@googlegroups.com
@Stefan - you might be correct, because Tasker v5.6 still pulls normally-set alarms.

Do you have reliable alarms set to, "always"? If not, there might be a different API you can hit; otherwise, this would need to be addressed in a future app update. 

On Sat, Feb 2, 2019, 9:44 AM Stefan <s.hoc...@gmail.com> wrote:
Unfortunately getNextAlarmClock() also returns the time of the next time context used in Tasker - at least in the current beta release.

--
You received this message because you are subscribed to a topic in the Google Groups "Tasker" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/tasker/5ecIH9fyn5M/unsubscribe.
To unsubscribe from this group and all its topics, send an email to tasker+un...@googlegroups.com.
Visit this group at https://groups.google.com/group/tasker.
For more options, visit https://groups.google.com/d/optout.

Stefan

unread,
Feb 2, 2019, 10:12:48 AM2/2/19
to Tasker
Yes, I've set Use Reliable Alarms to Always. If I set it to never I'm actually getting the next alarm time from the alarm clock and not the next occurring time context in Tasker.

Jeffrey Eng

unread,
Feb 2, 2019, 10:17:39 AM2/2/19
to tas...@googlegroups.com
Nice! So did we solve this?

In the past, I noticed that my clock widget (Chronus) would show mysterious alarms that I never set myself. When use reliable alarms is set to always, it looks like Tasker will set a hidden alarm, and that is likely what the method was returning as a result.


On Sat, Feb 2, 2019, 10:13 AM Stefan <s.hoc...@gmail.com> wrote:
Yes, I've set Use Reliable Alarms to Always. If I set it to never I'm actually getting the next alarm time from the alarm clock and not the next occurring time context in Tasker.

Stefan

unread,
Feb 2, 2019, 1:16:33 PM2/2/19
to Tasker
Yes and No :)

Thank you for pointing out the issue with Tasker's Reliable Alarms setting and maybe with other apps using this feature!

But still looking for the solution how to find out reliably when the next alarm of the alarm clock will be.

Duckredbeard

unread,
Feb 2, 2019, 1:28:49 PM2/2/19
to Tasker
I use the app "Wake me up! " because it has great tasker integration.

Duckredbeard

unread,
Feb 2, 2019, 1:33:46 PM2/2/19
to Tasker

Look at the variable it reports!

Screenshot_20190202-133236.jpg

Alexander Graetz

unread,
Feb 2, 2019, 2:17:02 PM2/2/19
to Tasker
Just make sure you read the next alarm clock while the screen is on and you're good to go

João Dias

unread,
Feb 4, 2019, 10:14:26 AM2/4/19
to tas...@googlegroups.com
You should:

- disable reliable alarms
- wait a few seconds
- check next alarm
- enable reliable alarms :)

Thank you for your contact.

   Join: connect multiple devices (send pushes, remote SMS, notifications) on Android, Windows, Mac, Linux
   Tasker: customize/automate anything on your phone!
   AutoApps: add advanced functionality to Tasker via plugins

     

João Dias


On Sat, Feb 2, 2019 at 7:17 PM Alexander Graetz <agra...@gmail.com> wrote:
Just make sure you read the next alarm clock while the screen is on and you're good to go

--
You received this message because you are subscribed to the Google Groups "Tasker" group.
To unsubscribe from this group and stop receiving emails from it, send an email to tasker+un...@googlegroups.com.

Alexander Graetz

unread,
Feb 4, 2019, 1:36:24 PM2/4/19
to Tasker
I think I remember that disabling reliable alarms does not clear the next alarm set by Tasker. This is done when turning on the display.

João Dias

unread,
Feb 4, 2019, 1:40:57 PM2/4/19
to tas...@googlegroups.com
Hmm, weird, my method works on my devices at least!


Thank you for your contact.

   Join: connect multiple devices (send pushes, remote SMS, notifications) on Android, Windows, Mac, Linux
   Tasker: customize/automate anything on your phone!
   AutoApps: add advanced functionality to Tasker via plugins

     

João Dias

On Mon, Feb 4, 2019 at 6:36 PM Alexander Graetz <agra...@gmail.com> wrote:
I think I remember that disabling reliable alarms does not clear the next alarm set by Tasker. This is done when turning on the display.

Reply all
Reply to author
Forward
0 new messages