wear-osgoogle-fitsamsung-galaxy-watch-4

Google fit api doesn't work on galaxy watch 4


I'm developing app for watch 4 and I want to use google fit api, but it doesn't work. When I try to create recording, sensors, history and other clients and subscribe to the sensors (ex: OXYGEN_SATURATION or STEP_COUNT or TYPE_HEART_RATE_BPM ) (by this guide: https://developers.google.com/fit/android/api-client-example), I get this error:

API: Fitness.CLIENT is not available on this device. Connection failed with: ConnectionResult{statusCode=INVALID_ACCOUNT, resolution=null, message=null}.

I accepted all permission for google fit sensors. I use galaxy watch4 classic (sm-r880) (bought in Russia).

I tried to build and launch this app on the galaxy s9 (sm-g960f) and it's working fine, I don't get this error when launch the same code and I can create clients and subscribe to the sensors. I used the same google account for mobile and watch.

I prepared logs that I collected via logcat from watch 4 and galaxy 9. You can find in the watch logs that any client are not available

2021-11-15 20:03:57.683 3268-3268/com.test.app.watch E/RCPLog: MainActivity.invokeSuspend() -> addOnFailureListener it: 17: API: Fitness.CLIENT is not available on this device. Connection failed with: ConnectionResult{statusCode=INVALID_ACCOUNT, resolution=null, message=null}

2021-11-15 20:03:57.752 3268-3268/com.test.app.watch E/RCPLog: MainActivity.onCreate() -> addOnFailureListener it: 17: API: Fitness.RECORDING_CLIENT is not available on this device. Connection failed with: ConnectionResult{statusCode=INVALID_ACCOUNT, resolution=null, message=null}

2021-11-15 20:03:57.779 3268-3268/com.test.app.watch E/RCPLog: MainActivity.onCreate() -> addOnFailureListener it: 17: API: Fitness.SESSIONS_CLIENT is not available on this device. Connection failed with: ConnectionResult{statusCode=INVALID_ACCOUNT, resolution=null, message=null}

2021-11-15 20:03:57.850 3268-3268/com.test.app.watch E/RCPLog: MainActivity.onCreate() -> Find data sources request failed e com.google.android.gms.common.api.ApiException: 17: API: Fitness.SENSORS_CLIENT is not available on this device. Connection failed with: ConnectionResult{statusCode=INVALID_ACCOUNT, resolution=null, message=null}

But on the galaxy 9 all works fine and I can see logs like this "addOnSuccessListener" not like this "addOnFailureListener" (the same code):

2021-11-15 20:13:05.020 32276-32276/com.test.app.watch E/RCPLog: MainActivity.invokeSuspend() -> addOnSuccessListener

2021-11-15 20:13:05.020 32276-32276/com.test.app.watch E/RCPLog: MainActivity.onCreate() -> addOnSuccessListener

2021-11-15 20:13:05.020 32276-32276/com.test.app.watch E/RCPLog: MainActivity.onCreate() -> Data source found: raw:com.google.heart_rate.bpm:samsung:SM-G960F:de5dc392:HeartRate Sensor

2021-11-15 20:13:05.020 32276-32276/com.test.app.watch E/RCPLog: MainActivity.onCreate() -> Data Source type: com.google.heart_rate.bpm

2021-11-15 20:13:05.021 32276-32276/com.test.app.watch E/RCPLog: MainActivity.onCreate() -> Data source for TYPE_HEART_RATE_BPM found!

2021-11-15 20:13:05.039 32276-32276/com.test.app.watch E/RCPLog: MainActivity.onCreate() -> addOnSuccessListener`

https://www.dropbox.com/s/cd6mv6eebib11gc/Logs_from_galaxy_9.txt?dl=0

https://www.dropbox.com/s/yk7q08n57amdoqo/Logs_from_watch4.txt?dl=0

Maybe I use google fit api wrong, but why the same code are working on the mobile device and not working on the watch? Maybe google fit api doesn't work on the galaxy watch4?

Thanks!


Solution

  • From what I understand the Samsung Galaxy Watch 4 doesn't have the Google Fit APIs (and probably never will). Instead, it ships with Samsung Health. I haven't worked with Samsung Health and don't know if there is an API that you can use instead on that specific device. You can find more details about Samsung Health here and hopefully figure out if it allows you to do the same things that you currently rely on Google Fit for.

    In the future you might be able to use the new Health Services API instead but that's still in alpha.