Add alarm entry to system clock app

1,194 views
Skip to first unread message

Bernhard Kriechbaum

unread,
Jan 14, 2021, 3:35:28 PM1/14/21
to DroidScript
Hi guys,

Is there any possibility to add a new alarm ( or set the timer) to the system clock app?

Actually I tried the app.sensintent feature but I don't have any idea which paras I have to set :/

Thanks for help

Rgda

Alan Hendry

unread,
Jan 15, 2021, 4:16:39 AM1/15/21
to DroidScript
Hi,
I presume you want to set an alarm in the clock (not an event in the Calendar).
is written for B4x (basic) so will need translating to DS (Javascript)
    i.Initialize("android.intent.action.SET_ALARM", "")
    i.PutExtra("android.intent.extra.alarm.HOUR", 20)
    i.PutExtra("android.intent.extra.alarm.MINUTES", 35)
    i.PutExtra("android.intent.extra.alarm.MESSAGE","My Alarm")
    i.PutExtra("android.intent.extra.alarm.SKIP_UI", True)
Regards, ah

Cemal

unread,
Jan 15, 2021, 4:21:15 AM1/15/21
to DroidScript
Something like this has to happen.
For type I tried the following: int, integer, string, number
But giving error: WARNING: App.SendIntent() failed! (Unterminated array at character 9 of [object Object],[object Object])
And this permission may be required: SET_ALARM

//Called when application is started.
function OnStart()
{
    action = "android.intent.action.SET_ALARM"
    extras = [
        {name: "android.intent.extra.alarm.HOUR", type: "number", value: "17"},
        {name: "android.intent.extra.alarm.MINUTES", type: "number", value: "11"}
    ]
    app.SendIntent(null, null, action, null, null, null, extras);
}


15 Ocak 2021 Cuma tarihinde saat 12:16:39 UTC+3 itibarıyla hendr...@gmail.com şunları yazdı:

Alan Hendry

unread,
Jan 15, 2021, 6:39:17 AM1/15/21
to DroidScript
Hi,
(I'm not an expert, but I've coded and tested other intents, so far without extras).
Other posts include a directive
_AddPermissions("Storage") ;
You may need to experiment (or search the web for the correct value) unless some-one else knows.
https://github.com/DroidScript/Docs/blob/master/files/en/intro/02%20App%20Events.md
has an example of receiving an intent (it may give some clues on how to send extras).
The extras seem to be a JSON list of {name, type, value}
You have values "17" and "11" - you could try without the quotes
hints that the types are "boolean", "int", "Uri", "Parcelable" and "String" (may need to play with capitalization)  
I would presume the HOUR and MINUTE are numeric, a MESSAGE string may be required, SKIP_UI a boolean to skip user seeing clock app.
If you get it working, could you post a snippet of code?
Regards, ah

Alan Hendry

unread,
Jan 17, 2021, 10:57:10 AM1/17/21
to DroidScript
Hi,
If you compare the extras json above with the lang.json file 
https://symdstools.github.io/Docs/docs/intro/07FileStructure.htm#lang.json
I think there should be quotes around "name" "type" "value"
Not sure if it should start with [ or {  , and end with ] or } 
Regards, ah

Dave

unread,
Jan 17, 2021, 11:13:23 AM1/17/21
to DroidScript
Unfortunately the Wiki is down at the moment (we have plans to restore it) so you can't see the examples there.  But this code snippet from inside DS should help you work out the parameter names and types:-

if( type.equals("string" ) ) i.putExtra( name, value );
else if( type.equals("float" ) ) i.putExtra( name, Utils.ToFloat(value) );
else if( type.equals("int" ) ) i.putExtra( name, Utils.ToInt(value) );
else if( type.equals("long" ) ) i.putExtra( name, Utils.ToLong(value) );
else if( type.equals("bool" ) ) i.putExtra( name, Utils.ToBool(value) );
else if( type.equals("list" ) ) i.putExtra( name, value.split(",") );
else if( type.equals("file" ) ) i.putExtra( name, Uri.parse("file://" + value) );
else if( type.equals("keydown" ) ) i.putExtra( name, new KeyEvent(KeyEvent.ACTION_DOWN, Utils.ToInt(value)) );
else if( type.equals("keyup" ) ) i.putExtra( name, new KeyEvent(KeyEvent.ACTION_UP, Utils.ToInt(value)) );

So you that you can see that you should not be using "number" but "int" or "long" probably (check the Android docs)

@Symbroson, can we get the extras types listed in the DS docs please

Cemal

unread,
Jan 17, 2021, 11:14:13 AM1/17/21
to DroidScript
Hi,
You can look DroidScript > Samples > Send Intent

This permission require to declare manifest.
com.android.alarm.permission.SET_ALARM
17 Ocak 2021 Pazar tarihinde saat 18:57:10 UTC+3 itibarıyla hendr...@gmail.com şunları yazdı:

Dave

unread,
Jan 17, 2021, 11:18:21 AM1/17/21
to DroidScript
_AddPermissions(  "Alarms" )  will get you that permission in an APK.  The DS IDE already has that permission.

Bernhard Kriechbaum

unread,
Jan 17, 2021, 1:51:29 PM1/17/21
to DroidScript
Hi all,

thanks for your answers.

i already found the sample " DroidScript > Samples > Send Intent ",- that give´s me some introduction, which parameter i need.

i´m also able to open the "clock" - app by following code:

 

//Called when application is started.
function OnStart()
{
var packageName="com.sec.android.app.clockpackage";
 var className="com.sec.android.app.clockpackage.ClockPackage";
    var action ="SHOW_TIMERS";
    var category = null;
    var uri = null;
    var type = null;
    
    var extras = [ 
//        {name:"android.intent.extra.alarm.EXTRA_HOUR",  type:"integer",value:"17"},
  //     {name:"android.intent.extra.alarm.EXTRA_MINUTES", type:"integer", value:"00"}
//   {name:"android.intent.extra.alarm.LENGTH",type:"integer",value:"30000"}
//{name:"android.intent.extra.alarm.MESSAGE",type:"string",value:"testest"}
        ];
  extras = JSON.stringify( extras );
  
    app.SendIntent( packageName, className, action, category, uri, type, extras ) 

}

unfortunately, only the clock app opens, but the app don´t change in the right tab nor set the timer or alarm entry.

so, something about the para list isnt correct.
@Dave: i already checked the docs ( link: https://developer.android.com/reference/android/provider/AlarmClock#ACTION_SET_TIMER) ,- it should be an "integer",- but also tried 
*)"number", "int" , "integer" (leave "type" away) 
*) leave the quotes away from "value" and/or "type"

some information, is getting me also struggling:

the docs are talking about a constant value "Constant Value: "android.intent.extra.alarm.HOUR".
but the headline of the parameter is "public static final String EXTRA_HOUR"

1.) what is the correct variable - name finally? ( HOUR or EXTRA_HOUR)
2.) what´s the correct data type ? String?(= from my opinion, the vlaues have to be with quotes) or integer?

very confusing this topic... ( but we are talking about just setting a alarm... what about real complicate app - intents ? :-O)

rgds

Bernhard

Cemal

unread,
Jan 17, 2021, 2:08:21 PM1/17/21
to DroidScript
I get this error if without extras:
WARNING: App.SendIntent() failed! 
(Permission Denial: 
starting Intent { act=android.intent.action.SET_ALARM cmp=com.google.android.deskclock/com.android.deskclock.HandleSetApiCalls } 
from ProcessRecord{8339b68 6917:com.smartphoneremote.androidscriptfree:NewActivityProcess/u0a64} 
(pid=6917, uid=10064) 
requires com.android.alarm.permission.SET_ALARM)

17 Ocak 2021 Pazar tarihinde saat 21:51:29 UTC+3 itibarıyla bpmkk...@gmail.com şunları yazdı:

Bernhard Kriechbaum

unread,
Jan 17, 2021, 2:15:26 PM1/17/21
to DroidScript
Where do you see the error? If i am clicking the "bug" button to start the app, I don't get any error

Rgds

Cemal

unread,
Jan 17, 2021, 2:21:36 PM1/17/21
to DroidScript
Try WiFi IDE

17 Ocak 2021 Pazar tarihinde saat 22:15:26 UTC+3 itibarıyla bpmkk...@gmail.com şunları yazdı:

Alan Hendry

unread,
Jan 18, 2021, 5:51:23 AM1/18/21
to DroidScript
Hi,
Java seems to have constants built in
There's  ACTION_SET_TIMER  "android.intent.action.SET_TIMER" with parameters
  • EXTRA_LENGTH (optional): The length of the timer being set.   "android.intent.extra.alarm.LENGTH"  Integer and ranges from 1 to 86400 (24 hours).
  • EXTRA_MESSAGE (optional): A custom message for the timer.  "android.intent.extra.alarm.MESSAGE"  String
  • EXTRA_SKIP_UI (optional): Whether or not to display an activity for setting this timer.  "android.intent.extra.alarm.SKIP_UI"  Boolean
And ACTION_SET_ALARM "android.intent.action.SET_ALARM" with parameters
  • EXTRA_HOUR (optional): The hour of the alarm being set.  "android.intent.extra.alarm.HOUR"  Integer and ranges from 0 to 23.
  • EXTRA_MINUTES (optional): The minutes of the alarm being set.  "android.intent.extra.alarm.MINUTES" 
  • EXTRA_DAYS (optional): Weekdays for repeating alarm.  
  • EXTRA_MESSAGE (optional): A custom message for the alarm.   as above
  • EXTRA_RINGTONE (optional): A ringtone to play with this alarm. 
  • EXTRA_VIBRATE (optional): Whether or not to activate the device vibrator for this alarm.  
  • EXTRA_SKIP_UI (optional): Whether or not to display an activity for setting this alarm. As Above
Regards, ah

Cemal

unread,
Jan 18, 2021, 6:52:52 AM1/18/21
to DroidScript
This permission declared in DroidScript:
android.permission.SET_ALARM
But we need this:
com.android.alarm.permission.SET_ALARM
18 Ocak 2021 Pazartesi tarihinde saat 13:51:23 UTC+3 itibarıyla hendr...@gmail.com şunları yazdı:

Bernhard Kriechbaum

unread,
Jan 18, 2021, 2:03:42 PM1/18/21
to DroidScript
Thanks for copy /paste the content of my link...
I already read this, but how to handle the paras and intent from DS?

Rgds
Bernhard

Bernhard Kriechbaum

unread,
Jan 18, 2021, 2:05:59 PM1/18/21
to DroidScript
So...? DS bug? Or can I just add the required permission manually?
If you check the doc from "GetPermission": there are just a few valid types available...

Rgds

Bernhard



Alan Hendry

unread,
Jan 19, 2021, 5:31:51 AM1/19/21
to DroidScript
Hi,
I have a small app that displays incoming broadcasts 
(format of JSON may be different in send intent and receive intent - so take this with a pinch of salt) 
Screen shot shows JSON sent by broadcast of volume change
Doesn't seem to include strings name: or value: and no type: entry at all
Following this format you could try
extras = {"android.intent.extra.alarm.HOUR" : "17", "android.intent.extra.alarm.MINUTES" : "11"}
Dunno if there's a complete list of permissions. There's a long list at
but it doesn't seem to mention clock or time.
Regards, ah
Screenshot_20210119-093007.jpeg

Alan Hendry

unread,
Jan 20, 2021, 6:16:50 AM1/20/21
to DroidScript
Hi,
says the permission should be 
com.android.alarm.permission.SET_ALARM 
If _AddPermissions("SET_ALARM") doesn't work you could try the above in manifest.xml or perhaps app.GetPermission 
Regards, ah

Dave

unread,
Jan 20, 2021, 7:38:55 AM1/20/21
to DroidScript
Ahhh, sorry guys, I did not notice that unusual permission format. (It's unlike all the others for some reason)

That permission will be in the next alpha release (probably coming later this week)

If you can't wait, then you could use one of those manifest hacking apps to add it yourself. Or if you have a PC you can use the APKTool utility to add or remove any permissions you like.

Alan Hendry

unread,
Jan 20, 2021, 8:35:48 AM1/20/21
to DroidScript
Hi,
has a long list of permissions (for future reference).
Most start with android.permission but quite a few start with other strings, for example
com.android.alarm.permission.SET_ALARM  
com.android.browser.permission.READ_HISTORY_BOOKMARKS (and WRITE)
permission:com.android.launcher.permission.INSTALL_SHORTCUT (and UNINSTALL)
permission:com.android.launcher3.permission.READ_SETTINGS  (and WRITE)
com.android.voicemail.permission.ADD_VOICEMAIL (and READ and WRITE)
Regards, ah

Alan Hendry

unread,
Feb 4, 2021, 5:59:45 AM2/4/21
to DroidScript
Bernhard,
I don't know if you're signed up for beta, the latest beta (203b1) has a bunch of changes/fixes that include
Fixed SET_ALARM permission having wrong path.  
You can sign up to the beta forum by sending an email asking to join
see https://groups.google.com/g/androidscript/c/aE9XfxBhhno/m/7DIKIlKIAwAJ for a link to the email address (hidden against robots)
Beta versions include fixes and new functions, they are released for more people to test on different phones, different versions of Android etc.
There may be bugs (usually in new functions), but if you need the fix quickly, you can join up and try it.
Regards, ah

Alan Hendry

unread,
Mar 10, 2021, 6:06:54 AM3/10/21
to DroidScript
Hi,
Version 2.03 was released to production a while ago.
The code posted in the Beta group by Cemal should now work in the production version of DS.
But the parameter skipUI seems to be ignored, so it shows the user the Alarm app with the alarm showing.
(setting a timer with SET_TIMERLENGTHMESSAGESKIP_UI also works, but skipUI seems to be ignored)

_AddPermissions("Alarms") // For APK

// Called when application is started.
function OnStart()
{
    app.AddAlarmToClock(17, 11, "Wake Up!", true)
}

/**
 * Add alarm to clock.
 * 
 * @param {Number}  hours   Alarm hours.
 * @param {Number}  minutes Alarm minutes.
 * @param {String}  message Alarm message.
 * @param {Boolean} skipUI  Skip alarm UI.
 */
app.AddAlarmToClock = function(hours, minutes, message, skipUI) {
    const extras = [
        {name: "android.intent.extra.alarm.HOUR", type: "int", value: hours || 0},
        {name: "android.intent.extra.alarm.MINUTES", type: "int", value: minutes || 0}
    ]
    
    if(message)
        extras.push({name: "android.intent.extra.alarm.MESSAGE", type: "string", value: message})
    
    if(skipUI) // Maybe.
        extras.push({name: "android.intent.extra.alarm.SKIP_UI", type: "boolean", value: true})
    
    app.SendIntent(null, null, "android.intent.action.SET_ALARM", null, null, null, JSON.stringify(extras))
}

Regards, ah

Reply all
Reply to author
Forward
0 new messages