Skip to content

Commit 1f5cbcc

Browse files
authored
add workout[experimental] doc
1 parent db0d2f8 commit 1f5cbcc

File tree

1 file changed

+74
-1
lines changed

1 file changed

+74
-1
lines changed

Diff for: README.md

+74-1
Original file line numberDiff line numberDiff line change
@@ -695,7 +695,80 @@ GoogleFit.getMoveMinutes(opt).then((res) => {
695695
}
696696
]
697697
```
698-
#### 17. Other methods:
698+
#### 17. Workout [Experimental]:
699+
Fields may be **inconsistent** and **overwrite** by Google Fit App, it could be `bugs` or some internal processes that we are not aware of.
700+
<br/>**That's why it's experimental. Use at your own risk.**
701+
<br/>[List of ActivityType](https://github.com/StasDoskalenko/react-native-google-fit/blob/db0d2f8cf090e5f62e8115cfba2fc0cc454fb922/index.android.d.ts#L509)
702+
<br/>[List of Session Activities from official Doc](https://developers.google.com/android/reference/com/google/android/gms/fitness/FitnessActivities#ERGOMETER)
703+
704+
**Add:**
705+
```javascript
706+
GoogleFit.saveWorkout({
707+
startDate: startDate,
708+
endDate: endDate,
709+
sessionName: `session name`,
710+
// below example is probably not unique enough, must be **UUID**
711+
identifier: `session:${Date.now()}-${dataType}:${startDate}-${endDate}`,
712+
activityType: ActivityType.Meditation, //dataType
713+
description: `some description`,
714+
// options field
715+
calories: 233, // most consistent field across all activities
716+
steps: 600, // may not working, for example: ActivityType.Meditation doesn't have step by default
717+
// experimental field
718+
// this may not work or overwrite by GoogleFit App, it works in ActivityType.Other_unclassified_fitness_activity
719+
intensity: 1 // display as heart points in Google Fit app
720+
});
721+
```
722+
**Deletion:**
723+
<br />Warning: Deletion is an async actions, Oftentimes the deletion would not happen immediately.
724+
```javascript
725+
await GoogleFit.deleteAllWorkout({
726+
startDate: startDate,
727+
endDate: endDate,
728+
})
729+
```
730+
**Get Workout:**
731+
<br/>This is **complemental** method to `getActivitySamples()`, For some unknown reasons, both were missing some data or have incorrect data.
732+
<br/>Try to use both to create a full picture if neccessary
733+
```javascript
734+
await GoogleFit.getWorkoutSession(actOptions)({
735+
startDate: startDate,
736+
endDate: endDate,
737+
})
738+
```
739+
740+
func | session Id | session name | session identifier | description | duration | intensity | calories, steps. etc.
741+
------- | ------------- | ------------ | ------------- | ------------ | ------------- | ------------ | ------------- |
742+
getActivitySamples() | ❌ | ❌ | ❌ | ❌ | ✔️ | ✔️ | ✔️
743+
getWorkoutSession() | ✔️ | ✔️ | ✔️ | ✔️ | ❌ | ❌ | ✔️
744+
745+
---
746+
747+
There is not such a update workout method if the workout exists in a session based on current investigation.
748+
<br/>So if you want to do an update, you can try to do delete then create based on the old session timestamp
749+
750+
```javascript
751+
// startDate & endDate are from the existing session you want to modify
752+
const options = {
753+
startDate: startDate,
754+
endDate: endDate,
755+
sessionName: `new session name`,
756+
identifier: `session:${Date.now()}-${dataType}:${startDate}-${endDate}`, // UUID
757+
activityType: ActivityType.Meditation, //dataType
758+
description: `new description`,
759+
.....
760+
newData
761+
};
762+
763+
const del = await GoogleFit.deleteAllWorkout(options);
764+
765+
if(del) {
766+
const result = await GoogleFit.saveWorkout(options);
767+
console.log(result)
768+
}
769+
```
770+
771+
#### Other methods:
699772

700773
```javascript
701774
observeSteps(callback); // On Step Changed Event

0 commit comments

Comments
 (0)