FitnessSensorService not being started by Android OS

I am attempting to write a fitness application that incorporates Google Fit. The app is related to a wearable that tracks basic step count. In our test harness in Android Studio we have the following related service that is started automatically by the Android OS.

From manifest of Android Studio Project Test-App:

<service android:name=".lggfit.LgGoogleFitSensor"
          android:label="LgGoogleFitSensor"
          android:exported="true"
          android:enabled="true"
          android:process=":sensor">
        <intent-filter>
            <action android:name="com.google.android.gms.fitness.service.FitnessSensorService" />
            <data android:mimeType="vnd.google.fitness.data_type/com.google.step_count.delta" />
        </intent-filter>
   </service>

This does start the service which is then used by the app in other code to send step counts to the Google Fit app (FitnessSensorService). However, attempting to start the same service from the Unity App results in the service not being started.

From manifest of Unity Project:

<service android:name="com.sensorstar.stephen.lgbluetoothlib.lggfit.LgGoogleFitSensor"
     android:label="LgGoogleFitSensorService"
     android:enabled="true"
     android:exported="true"
     android:process=":sensor">
    <intent-filter>
      <action android:name="com.google.android.gms.fitness.service.FitnessSensorService" />
      <data android:mimeType="vnd.google.fitness.data_type/com.google.step_count.delta" />
    </intent-filter>
  </service>

After poking around a few days, attempting to do what I can to rule out various components, even going as far as generating a Unity-Android Studio project and ripping out everything but a few key files; I am still at a lost as to why the service is not being started.

My question: Is there something with Unity that prevents OS-started services from running? Or something incompatible between Unity and the way the FitnessSensorService works?

So it turns out that testing the FitnessSensorService in the test app caused some interference when attempting to start a similar service from the Unity app (with no errors of course). I had to Uninstall the test app and restart my phone to completely remove its service. After that the service started by the Untiy app was working as expected.

1 Like

Hi SCowan,
Can u give some lights that how can you achieve this. I also want to use google fit data in unity App.
Thank you.