Cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Switch from clockface to app (like Alarm or timer)

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

Best Answer
0 Votes
16 REPLIES 16

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.

Peter McLennan
Gondwana Software
Best Answer
0 Votes

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

Best Answer
0 Votes

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).

Peter McLennan
Gondwana Software
Best Answer
0 Votes

@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,

Best Answer
0 Votes

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

Best Answer
0 Votes

@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,

Best Answer
0 Votes

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,

 

 

Best Answer
0 Votes

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
  }
}
Best Answer
0 Votes

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.

Peter McLennan
Gondwana Software
Best Answer
0 Votes

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

Best Answer
0 Votes

@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,

Best Answer
0 Votes

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.

Best Answer

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.

Best Answer
0 Votes

@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.

Best Answer
0 Votes

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.

Peter McLennan
Gondwana Software
Best Answer
0 Votes

@Gondwana  thanks Peter, it's possible to get permission then.

 

The question is how to go about it.

 

There seems to be no channel in the community for that?

Author | ch, passion for improvement.

Best Answer
0 Votes