Google Fit data no reading from cloud, only reading locally

308
August 11, 2017, at 07:07 AM

I'm currently having trouble using HistoryApi from google fitness. I'm trying to read back heart rate data from a certain time range and also heart rate summary information. Everything seems to be ok when reading back data which seems to be local to the device (android wear watch syncs via this device), but when I try and use another device or the emulator nothing is returned although the status reads success.

Is there are any way of reading data which has been taken on a differernt device, like the fit.google.com webpage does.

Here is the connection setup and auth. (Language is Kotlin)

fitApiClient = GoogleApiClient.Builder(activity)
            .addApi(Fitness.HISTORY_API)
            .addScope(Scope(Scopes.FITNESS_BODY_READ))
            .useDefaultAccount()
            .addConnectionCallbacks(object : GoogleApiClient.ConnectionCallbacks {
                override fun onConnected(initialBundle: Bundle?) {
                    connectionResultPublishSubject.onNext(ConnectionUpdate.onConnected())
                }
                override fun onConnectionSuspended(cause: Int) {
                    connectionResultPublishSubject.onNext(ConnectionUpdate.onSuspended(cause))
                }
            })
            .addOnConnectionFailedListener { result ->
                connectionResultPublishSubject.onNext(ConnectionUpdate.onFailed(result)) }
            .build()
fitApiClient.connect()

Here is the data request for heart rate data.

return Observable.create({
        val readRequest = DataReadRequest.Builder()
                .setTimeRange(startTime, endTime, TimeUnit.MILLISECONDS)
                .read(DataType.TYPE_HEART_RATE_BPM)
                .enableServerQueries()
                .build()
        val result = Fitness.HistoryApi.readData(fitApiClient, readRequest)
        result.setResultCallback({
            resultData ->
            it.onNext(resultData)
            it.onComplete()
        }, 30, TimeUnit.SECONDS)
    })

Here is the result from the device which recorded the data.

DataReadResult{status=Status{statusCode=SUCCESS, resolution=null}, dataSets=[DataSet{d:heart_rate.bpm:gms:default_heart_rate_bpm 48 data points, first 5: [RawDataPoint{[73.0]@[1502344904955000000, 1502344904955000000](0,1)}, RawDataPoint{[68.0]@[1502345462568000000, 1502345462568000000](0,1)}, RawDataPoint{[72.0]@[1502345716511000000, 1502345716511000000](0,1)}, RawDataPoint{[61.0]@[1502346207125000000, 1502346207125000000](0,1)}, RawDataPoint{[58.0]@[1502346523555000000, 1502346523555000000](0,1)}]}], buckets=[]}

Here is the result from a device without local google fit data

DataReadResult{status=Status{statusCode=SUCCESS, resolution=null}, dataSets=[DataSet{d:heart_rate.bpm:gms:default_heart_rate_bpm []}], buckets=[]}

Version of google play services is 'com.google.android.gms:play-services-fitness:11.0.4'

Thanks for any help in advance

Rent Charter Buses Company
READ ALSO
Not getting rssi after connecting to a ble peripheral simulated on an android device

Not getting rssi after connecting to a ble peripheral simulated on an android device

I have two android devices: Device A and Device BI am running a BLE Peripheral Simulator on device A

259
How to increase the size of a layout when more content is added to it in Kivy?

How to increase the size of a layout when more content is added to it in Kivy?

How do I change the size of the BoxLayout widget so that it scrolls vertically when more and more content is added to it? You can run the script below but keep adding more text and click send in order to see the behavior

334
How can we have autoscrolling effect in recycler view in android?

How can we have autoscrolling effect in recycler view in android?

I have a recycler view at which the adapter is added with an arraylist of 10 numbersThe recycler view should have smooth auto scrolling effect when I open the app

266
How to clear task and start new activity from widget

How to clear task and start new activity from widget

I have an application with the following activities

292