Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix crashes on Android(getHeartRate()) #108

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

# react-native-fitness
# react-native-fitness(fix crashes on Android by calling getHeartRate())
`react-native-fitness` is a library that works on both `iOS` and `Android` with it you can interact with Apple Healthkit and Google Fit.
Currently the lib provides a set of [API](#API) that you can use to read steps count or distance count for a given period of time.

Expand Down
13 changes: 7 additions & 6 deletions android/src/main/java/com/ovalmoney/fitness/manager/Manager.java
Original file line number Diff line number Diff line change
Expand Up @@ -485,13 +485,14 @@ private void processCalories(DataSet dataSet, WritableArray map) {
private void processHeartRate(DataSet dataSet, WritableArray map) {

for (DataPoint dp : dataSet.getDataPoints()) {
heartRateMap.putString("startDate", dateFormat.format(dp.getStartTime(TimeUnit.MILLISECONDS)));
heartRateMap.putString("endDate", dateFormat.format(dp.getEndTime(TimeUnit.MILLISECONDS)));
heartRateMap.putDouble("quantity", dp.getValue(dp.getDataType().getFields().get(0)).asFloat());
for(Field field : dp.getDataType().getFields()) {
WritableMap heartRateMap = Arguments.createMap();
heartRateMap.putString("startDate", dateFormat.format(dp.getStartTime(TimeUnit.MILLISECONDS)));
heartRateMap.putString("endDate", dateFormat.format(dp.getEndTime(TimeUnit.MILLISECONDS)));
heartRateMap.putDouble("quantity", dp.getValue(field).asFloat());
map.pushMap(heartRateMap);
}
heartRateMap.putDouble(field.getName(), dp.getValue(field).asFloat());
}
map.pushMap(heartRateMap);

}
}

Expand Down