@stridekick/react-native-health-connect
v0.1.18
Published
A bridge for the health platform api
Downloads
203
Keywords
Readme
react-native-health-connect-bridge
A bridge for the health platform api
Installation
npm install react-native-health-connect-bridge
Usage
import {
HealthPlatform
} from 'react-native-health-connect-bridge';
You will need to add the following to MainActivity
import com.healthconnectbridge.Utils.PermissionDelegate;
@Override
protected void onCreate(Bundle savedInstance) {
super.onCreate(null);
PermissionDelegate.INSTANCE.setPermissionDelegate(this,"com.google.android.apps.healthdata");
}
forms to generate dates
const getLastWeekDate = () => {
const getLastWeekDate = new Date(
new Date().getTime() - 7 * 24 * 60 * 60 * 1000
)
getLastWeekDate.setUTCHours(0, 0, 0, 0)
return getLastWeekDate
}
const getTodayDate = () => {
return new Date()
}
how to read data:
const readSampleData = async () => {
const grantedPermissions = await HealthPlatform.requestPermissions()
await HealthPlatform.getActivities({
timeRangeFilter: {
operator: 'between',
startTime: getLastWeekDate().toISOString(),
endTime: getTodayDate().toISOString(),
},
}).then((result) => {
console.log('Retrieved Activities: ', JSON.stringify({ result }, null, 2));
});
};
or
const readSampleData = async () => {
const grantedPermissions = await HealthPlatform.checkNecessaryPermission()
await HealthPlatform.getActivities({
timeRangeFilter: {
operator: 'after',
startTime: getLastWeekDate().toISOString()
},
}).then((result) => {
console.log('Retrieved Activities: ', JSON.stringify({ result }, null, 2));
});
};
or
const readSampleData = async () => {
const grantedPermissions = await HealthPlatform.requestPermissions()
await HealthPlatform.getActivities({
timeRangeFilter: {
operator: 'before',
endTime: getTodayDate().toISOString()
},
}).then((result) => {
console.log('Retrieved Activities: ', JSON.stringify({ result }, null, 2));
});
};
this will return :
{
"result": [
{
"steps": 23,
"distance": 200,
"date": "2024-02-06"
},
{
"steps": 1000,
"distance": 200,
"date": "2024-02-07"
},
{
"steps": 38,
"distance": 210.3600196838379,
"date": "2024-02-08"
},
{
"steps": 17,
"distance": null,
"date": "2024-02-09"
}
]
}
MIT
Made with create-react-native-library