06-05-2020 06:22
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

06-05-2020 06:22
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
Hello,
How we can develop an app like timer : I would like to make sure that when an event happens, the watch will switch on the application (even on a clockface) like Timer App.
Thanks 😉
Mike

06-05-2020 13:54
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post


06-05-2020 13:54
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
Your timer app/clockface would need to be running (is, visible) while in use, because clockfaces/apps can't run in the background.
However, it is possible for a clockface/app to start an app via an API call.
Gondwana Software

06-05-2020 14:12
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

06-05-2020 14:12
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
Thanks for your reply 😉.
But sorry, I don't understand 😔.
The app "timer" of fitbit display screen when the timer is 0. Even if the user is not on the app

06-05-2020 15:07
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post


06-05-2020 15:07
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
I'm afraid I don't understand either.
If you're referring to the official Fitbit Timer app on your watch, it's a special case and can do things that other apps can't do (such as stay running when some other clockface or app is running).
Gondwana Software

06-06-2020 08:36
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

06-06-2020 08:36
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
@Micka_Instance wrote:Hello,
How we can develop an app like timer : I would like to make sure that when an event happens, the watch will switch on the application (even on a clockface) like Timer App.
Thanks 😉
Mike
Hello Mike,
Not sure this will help, but I did have an issue that sounds like this.
You can't execute a background task, but you can have a trigger that fires then sets a delay so that it will fire correctly the next hour too:
var stpTO
,mPH=3600000
function prcS(resetTmr=true){
let crMs=(new Date()).getTime() //current time in milliseconds
let cHMs=Math.floor(crMs/mPH)*mPH //milliseconds at turn of current hour
// process here
if (resetTmr){
clearTimeout(stpTO) //Always clear timer variable
stpTO=setTimeout(prcS,(cHMs+mPH)-crMs)//Set timer to next hour
}
}
Also, you can launch an app from a watch face (or another app):
This argument is the UUID of the app. This specific one opens the weather app
import {launchApp} from "system"
launchApp("000013fe-0000-4000-8000-000000f17b17", {})
Regards,

06-07-2020 15:03
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

06-07-2020 15:03
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
Hello,
Thanks for you message. This code must be execute on compagnon or device?
I try to put this function on both with a console.log but on the simulator, the application close.
I checked "Run in background" permission.
The simulator don"t execute un background?
Regards

06-07-2020 18:07 - edited 06-07-2020 18:08
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

06-07-2020 18:07 - edited 06-07-2020 18:08
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
@Micka_Instance wrote:Hello,
Thanks for you message. This code must be execute on compagnon or device?
I try to put this function on both with a console.log but on the simulator, the application close.
I checked "Run in background" permission.
The simulator don"t execute un background?
Regards
Hello Micka,
I generally run this on the app, but I also use a version on the companion for recurring communications.
You have to assume either (app or comp) may be stopped or started at any time, so you have to check on startup if your time has elapsed while your program wasn't running.
Your application shouldn't close from using timers on either the app or the companion.
As far as I know, the simulator operates as though it is a foreground application.
If anything, the problem with the simulator is that it runs better than the real hardware,...
It's quite the conundrum; the simulator is an exceptional tool (one of the best) and it does speed up development over using hardware alone, but you do still have to check using the hardware to make sure the app actually runs in real life, renders as intended, isn't abnormally slow, or an excessive drain on the battery.
Regards,

06-08-2020 00:03
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

06-08-2020 00:03
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
Hello MorningReign,
I think I missed something because at home on the simulator, it does not work. When I quit the app, it really quits and the app doesn't run in the background.
I put your code on the App and Companion part with a console.log in it to see if I had something that was displayed when I left the application but nothing.
Did I miss something ?
Regards,

06-09-2020 00:15
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

06-09-2020 00:15
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
Hello,
My code on App :
/*
* Entry point for the watch app
*/
import document from "document";
let demotext = document.getElementById("demotext");
demotext.text = "Fitbit Studio rocks!";
var stpTO, mPH=6000;
prcS();
function prcS(resetTmr=true){
console.log("Passe");
let crMs=(new Date()).getTime(); //current time in milliseconds
let cHMs=Math.floor(crMs/mPH)*mPH; //milliseconds at turn of current hour
// process here
if (resetTmr){
clearTimeout(stpTO); //Always clear timer variable
stpTO=setTimeout(prcS,(cHMs+mPH)-crMs);//Set timer to next hour
}
}

06-09-2020 00:26
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post


06-09-2020 00:26
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
You can't run an app in the background on the watch.
You can sometimes get the Fitbit app to run your companion code every five minutes (at best), but your companion code can't start your watch code.
Gondwana Software

06-09-2020 06:00
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

06-09-2020 06:00
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
Thanks Peter,
I understand.
Why the official "Timer" can do it but not developer App ? It's because the security or some think like that ?
Mike

06-09-2020 19:50
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

06-09-2020 19:50
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
@Micka_Instance wrote:Thanks Peter,
I understand.
Why the official "Timer" can do it but not developer App ? It's because the security or some think like that ?
Mike
javaScript applications are by nature isolated (sandboxed) from the operating system except through very well defined API interfaces.
It's why the first time an app runs the user has to explicitly give permission to access things like location or the internet. This isolation makes javaScript 'safer' and less likely to be prone to virus or malware behavior.
Being able to run in the background after a user has switched to a different application would potentially give an app an extreme amount of power (and expose the publisher to an extreme amount of potential liability).
The Fitbit alarm application isn't really an exception to this isolation from the OS as it is more a part of the OS than not.
Regards,

08-07-2021 06:37
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post


08-07-2021 06:37
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
- Who Voted for this post?
Has there been any evolution in this area?
If the Fitbit Timer and Alarms can do it why can't anyone else? If an App can set a timer to run code while in foreground, why not be able to run that code from background?
I did manage to get SimpleTimer to work well as an Addon to SimpleClockPro but am still looking for it to run as a standalone too.
The problem with companion code is it ends when the App ends or ceases to work even before, if the phone is out of range.
Author | ch, passion for improvement.
08-09-2021 17:58
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

08-09-2021 17:58
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
Fitbit does now allow you to keep an app running in the foreground.
import {me} from "appbit";
me.appTimeoutEnabled = false
This works in my app. I wonder, for your timers, are you using Clock or Date to pull your time? I am going to add an alarm to my app eventually.

08-09-2021 19:37
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post


08-09-2021 19:37
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
@LekoFraggle thanks for your help, but the problem is if the user closes an app while it's doing something, it normally just stops doing it.
However got SimpleTimer to run in foreground using that method or to pseudo run in background to SimpleClockPro.
Now looking for a technical way to have it run in background to any clock or app, like the Fitbit Timer and Alarm.
It may need to have a special permission or access to do that, as we know it is possible to do it.
Author | ch, passion for improvement.

08-09-2021 19:43
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post


08-09-2021 19:43
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
Third-party apps don't have the ability to run in the background. Only apps by Fitbit or their partners (eg, for music) can get permission to do so.
Gondwana Software

08-09-2021 19:54
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post


