Skip to content

kader1303/react-native-health-connect

 
 

Repository files navigation

React Native Health Connect


This library is a wrapper around Health Connect for react native. Health Connect is an Android API and platform. It unifies data from multiple devices and apps into an ecosystem. For Android developers, it provides a single interface for reading and writing a user’s health and fitness data. For Android users, it offers a place for control over which apps have read and/or write access to different types of data. Health Connect also provides on-device storage. Read more here.

Requirements

  • Health Connect needs to be installed on the user's device, However the goal is to have this app preinstalled on Android devices in the future.
  • Health Connect API requires mindSdkVersion=26 (Android Oreo / 8.0).

Installation

Install react-native-health-connect by running:

yarn add react-native-health-connect@latest

Since this module is Android-only, you do not need to run pod install.

Example

A quick example at a glance:

import {
  initialize,
  requestPermission,
  readRecords,
} from 'react-native-health-connect';

const readSampleData = async () => {
  // initialize the client
  const isInitialized = await initialize();

  // request permissions
  const grantedPermissions = await requestPermission([
    { accessType: 'read', recordType: 'ActiveCaloriesBurned' },
  ]);

  // check if granted

  const result = await readRecords('ActiveCaloriesBurned', {
    timeRangeFilter: {
      operator: 'between',
      startTime: '2023-01-09T12:00:00.405Z',
      endTime: '2023-01-09T23:53:15.405Z',
    },
  });
  // {
  //   result: [
  //     {
  //       startTime: '2023-01-09T12:00:00.405Z',
  //       endTime: '2023-01-09T23:53:15.405Z',
  //       energy: {
  //         inCalories: 15000000,
  //         inJoules: 62760000.00989097,
  //         inKilojoules: 62760.00000989097,
  //         inKilocalories: 15000,
  //       },
  //       metadata: {
  //         id: '239a8cfd-990d-42fc-bffc-c494b829e8e1',
  //         lastModifiedTime: '2023-01-17T21:06:23.335Z',
  //         clientRecordId: null,
  //         dataOrigin: 'com.healthconnectexample',
  //         clientRecordVersion: 0,
  //         device: 0,
  //       },
  //     },
  //   ],
  // }
};

Alternatives

For iOS there are two alteranatives you can use which is very similar to Health Connect on Android. First one is @kingstinct/react-native-healhkit and the other one is react-native-health. These options are similar in functionality and can help you manage your health data on iOS.

Documentation

More examples and full documentation can be found here

Features

  • Typescript ✅
  • Supports both old and new architecture ✅

License

MIT

About

React native library for health connect (Android only)

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Kotlin 66.0%
  • TypeScript 24.3%
  • Java 3.9%
  • Shell 2.0%
  • Objective-C 1.2%
  • Ruby 1.0%
  • Other 1.6%