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

Companion app not starting

Hello All, 

 

I am developing an Fitbit app which uses the Excercise API. 

I am done developing the app. Things work fine as long as I am working with simulator. 

 

Now, I have installed the app on the device and also written a server code on my Android app and starting the server.

It's a workout app so I need to keep the Android app in the foreground. 

 

The problem, I need to keep the Fitbit companion app in foreground in order to receive events on the companion app. 

Can some one please guide, how can I go about it. 

 

I ll share my companion code here as well.

 

 

import * as messaging from "messaging";

messaging.peerSocket.onmessage = evt => {
   console.log("Evt ",evt);
   if (!evt.data)  return;
   var obj = evt.data;
   sendFetch(obj);
}

function sendFetch(data) {
  fetch('http://127.0.0.1:38302', {
          method: 'POST',
          body: JSON.stringify(data)
      }).then(function(response) {
          console.log(response.code);
          return response.json();
      }).then(function(json){
         console.log("Response from server : ",json);
   });
}

 

 

This is the example taken from fitbit excercise sdk example. 

 

I read this in the doc of the companion documentation, but I am not sure why I still can't get the events on the companion app and why I need to keep the companion app in the foreground. 

 

When an application is launched by the user, its associated companion is simultaneously launched on the mobile device. The companion can also subscribe to events which allow it to be woken even if the application is not currently running.

The following events which form part of the Life Cycle API and Wake Interval API can be used to wake the companion, and also determine why the companion was launched.

NOTE: A companion may not always be actively running due to mobile phone battery optimization. Companions can be launched with a life-cycle launch reason, or they may be already running and the life-cycle event will be emitted.

 

Alternatively, can someone guide me how can I launch the companion with a life-cycle launch reason peerAppLaunched.

 

It would be of great help, if someone can point in the right direction. 

Best Answer
0 Votes
1 REPLY 1

The app shouldn't need to be in the foreground but just running. You should check your mobile phone isn't performing aggressive battery optimisation and suspending the apps.

 

 

Best Answer
0 Votes