OvalMoney / react-native-fitness

A React Native module to interact with Apple Healthkit and Google Fit.
MIT License
341 stars 68 forks source link

How to get the real data of google fit? #84

Closed StarksJohn closed 3 years ago

StarksJohn commented 3 years ago

because you can add the number of fake steps in Google fit, so how do you make sure you use it Fitness.getSteps () the number of steps obtained is the actual sensor step number, not the number of steps added by the user?

StarksJohn commented 3 years ago

solved, I added this method to the file node_modules/@ovalmoney/react-native-fitness/android/src/main/java/com/ovalmoney/fitness/manager/Manager.java

public void readDailyTotalFromLocalDevice(Context context, final Promise promise){ Task response = Fitness.getHistoryClient(context, GoogleSignIn.getLastSignedInAccount(context)) .readDailyTotalFromLocalDevice(DataType.AGGREGATE_STEP_COUNT_DELTA); try { DataSet totalSet = Tasks.await(response, 1, SECONDS); WritableArray steps = Arguments.createArray(); processStep(totalSet, steps);

        //[{"endDate":"2020-11-30T13:50:52.044+0800","quantity":701,"startDate":"2020-11-30T06:59:14.358+0800"}]
        Log.v("Manager", "readDailyTotalFromLocalDevice steps= "+steps);
        promise.resolve(steps);
    } catch (InterruptedException e){
        e.printStackTrace();
    } catch (ExecutionException e) {
        e.printStackTrace();
    } catch (TimeoutException e) {
        e.printStackTrace();
    }
}