
Research
/Security News
Shai Hulud Strikes Again (v2)
Another wave of Shai-Hulud campaign has hit npm with more than 500 packages and 700+ versions affected.
capacitor-health-fit
Advanced tools
Capacitor plugin that allows to communicate with Healthkit and Google fit
This capacitor plugin allows you to communicate with healthkit or Google fit SDK.
npm install capacitor-health-fit
npx cap sync ios|android
Before you start to build your app, complete the steps in the following sections.
To use the Google Fit APIs, you need a Google Account. You can create a new account or use an existing account. You might want to create a separate account to test your app from a user's perspective.
Get the latest client library for Google Play services on your development host:
To enable the Fitness API, you need an OAuth 2.0 client ID.
Follow steps in Google Guide
We recommend using the Android Studio development environment to build an app with the Fitness API. For details on how to make a new project and configure it in Android Studio, see Create a project.



import {Plugins} from '@capacitor/core';
const {HealthFit} = Plugins;
...
HealthFit.getGeneralInformations()
.then(data => {
console.debug('Data received:', JSON.stringify(data));
})
.catch(e => alert(e));
Authorization types in the plugin (list in HealthFitAuthorizationDataType enum)
| Authorization name | iOS | Android |
|---|---|---|
| WEIGHT | HKQuantityTypeIdentifier.bodyMass | |
| STEP_COUNT | HKQuantityTypeIdentifier.stepCount | |
| ACTIVITY | HKQuantityTypeIdentifier.appleExerciseTime | |
| MINDFUL | HKCategoryTypeIdentifierMindfulSession | |
| GENERAL_INFORMATION | HKCharacteristicTypeIdentifier.biologicalSex & HKCharacteristicTypeIdentifier.dateOfBirth & HKCharacteristicTypeIdentifier.bloodType |
Samples avaivables in the plugin (list in HealthFitDataType enum)
| Sample name for query | unit | iOS | Android |
|---|---|---|---|
| WEIGHT | kilograms | HKQuantityTypeIdentifier.bodyMass | |
| STEP_COUNT | steps | HKQuantityTypeIdentifier.stepCount | |
| ACTIVITY | minutes | HKQuantityTypeIdentifier.appleExerciseTime | |
| MINDFUL | minutes | HKCategoryTypeIdentifierMindfulSession |
ACTIVITY represent move in minutes date return by Fit api
// Gender enum returned by getGeneralInformation method
export enum Gender {
notSet,
female ,
male,
other
}
// Blood type enum returned by getGeneralInformation method
export enum BloodType {
notSet,
aPositive,
aNegative,
bPositive,
bNegative ,
abPositive,
abNegative,
oPositive,
oNegative
}
// Return type of getGeneralInformation
export interface UserGeneralData {
data: {
birthday: Date,
bloodType?: BloodType, // BloodType only available on iOS
gender: Gender,
}
}
// List of all permissions that can be requested in the plugin
export enum HealthFitAuthorizationDataType {
WEIGHT = 'WEIGHT',
STEP_COUNT = 'STEP_COUNT',
ACTIVITY = 'ACTIVITY',
MINDFUL = 'MINDFUL',
GENERAL_INFORMATION = 'GENERAL_INFORMATION'
}
// List of all data types managed by the plugin
export enum HealthDataType {
WEIGHT = 'WEIGHT',
STEP_COUNT = 'STEP_COUNT',
ACTIVITY = 'ACTIVITY',
MINDFUL = 'MINDFUL',
}
// Possible return type when calling the read() or readMultiple() methods
// SUM of the WEIGHT is a forbidden action (this data does not make sense)
export enum HealthFitResultType {
ALL = 'ALL', // Returns a list with the details of all the data
SUM = 'SUM' // Returns an object with the sum of the data (example, the total number of steps over 1 day)
}
// Possible permission type when calling requestAuthorization
export enum HealthFitAuthorizationType {
READ = 'READ',
WRITE = 'WRITE'
}
// Return type for the read method
export interface HealthFitHistory {
data: HealthFitData[] | HealthFitData | {}; // "ALL" option return an Array, "SUM" option return the object or an empty one if no data.
}
// Return type for the readMultiple method
export type HealthFitMultipleHistory = {
[type in HealthFitDataType]: HealthFitData[] & HealthFitError[] | HealthFitData & HealthFitError | {}
}
// Detail of a data retrieved from health stores
export type HealthFitData = {
start: string, // 2021-11-16T10:34:35.973Z format
end: string, // 2021-11-16T10:34:35.973Z format
value?: number, // value is only optional for HealthFitDataType.MINDFUL
unit: string,
source?: string, // source available for a unique sample, but not for the sum of multiple samples
};
// Structure of error handling
export type HealthFitError = {
succeeded: boolean,
code?: string,
message?: string
}
Tells if HealthKit or Google fit is available on the device.
isAvailable(): Promise<{ available: boolean }>;
{type: function(available)}, available if true is passed, otherwise falseGoogle Fit is only available on sdk version upper to 24 (included)
Open health app (iOS only)
openHealth(): void;
Disconnect user and app from GoogleFit
disconnect(): Promise<void>;
Tells if the application has read and/or write permission for a datatype
isAuthorized(options : {type: String, mode: HealthFitAuthorizationType}): Promise<{authorized: boolean}>;
{type: function(authorized)}, authorized if true is passed, otherwise false{type: function(err)}, called if something went wrong, err can be :
HealthFitAuthorizationType.WRITE parameter and will only check the write permission. Read-only data authorization status can't be checked. This is an intended behaviour of HealthKit.Opens a page with the requested permissions (iOS) or a pop-up (Android), allows the user to allow or deny read or write access to one or more data.
requestAuthorization(options: { read: Array<string>; write: Array<string>; }): Promise<void>;
errorCallback: {type: function(err)}, called if something went wrong, err can be :
HealthFitDataType.ACTIVITY). It is therefore not possible to request a write authorization on this type of data.Gets all the data points of a certain datatype within a certain time window.
read(options: {type: string, start: Date, end: Date, result: string}): Promise<HealthFitHistory>;
{type: function(HealthFitHistory)} :
HealthFitResultType.ALL, the data key is a list of HealthFitData with all datapointsHealthFitResultType.SUM), the data key is HealthFitData object{type: function(err)}, called if something went wrong, err can be :
HealthFitDataType.WEIGHT with HealthFitResultType.SUM)Start and end dates in the HealthFitData response type matched with the real data found on GoogleFit Api inside the requested interval.
Request interval is exclusive. For example for an activity between 09:00 and 10:00, querying this exact interval will not return activity minutes, but 08:59 and 10:01 will.
Gets all the data points of multiple datatype within a certain datetime interval.
readMultiple(options: {types: Array<string>, start: Date, end: Date}): Promise<HealthFitMultipleHistory>;
{type: function(HealthFitMultipleHistory)} :
{type: function(err)}, called if something went wrong, err can be :
HealthFitDataType.BODY_MASS with HealthFitResultType.SUM)HealthFitDataType)Start and end dates in the HealthFitData response type matched with the real data found on GoogleFit Api inside the requested interval.
Request interval is exclusive. For example for an activity between 09:00 and 10:00, querying this exact interval will not return activity minutes, but 08:59 and 10:01 will.
Allows to retrieve the user's date of birth, gender and blood type
getGeneralInformation(): Promise<UserGeneralData>;
{type: function(UserGeneralData)} : Object containing data. blood type and gender are enumerations (BloodType, Gender).{type: function(err)}, called if something went wrong, err can be :
On Android, response object contain only birthday and gender. It's not possible to get bloodtype as it's not an available data.
Only public data can be retrieved.
Default visibility about gender and birthday is private. To change the visibility, follow theses steps:

Insert a data of a certain datatype within a certain time window.
insert(options: {type: string, value?: string, start?: Date, end?: Date}): Promise<{succeeded: boolean}>; // value is only optional for HealthFitDataType.MINDFUL
{type: function(success)} : Returns true if data added successfully, otherwise returns false{type: function(err)}, called if something went wrong, err can be :
HealthFitDataType.ACTIVITY on iOS)HealthFitDataType.ACTIVITY dataHealthFitDataType.BODY_MASS data is 345600 seconds. Beyond this limit, the NOT_AVAILABLE error is thrownHealthFitDataType.MINDFUL is 2419200 seconds. Beyond this limit, the NOT_AVAILABLE error is thrownBe sure to insert data into a free datetime interval. Whether the inserted pediod is:
Insert multiple data of multiple datatype within a certain time window.
insertMultiple(options: {list: Array<{ type: string; value: string, start?: Date, end?: Date }>}): Promise<{data: Array<HealthFitError & { index: number }>}>;
{type: function(Array<{success: boolean, error?: string})} : Returns a list containing the response to each insert (success or error, with reason for the error). An index is available and corresponds to the index of the input array.{type: function(err)}, called if something went wrong, err can be :
HealthFitDataType.ACTIVITY on iOS)HealthFitDataType)HealthFitDataType.ACTIVITY dataHealthFitDataType.BODY_MASS data is 345600 seconds. Beyond this limit, the NOT_AVAILABLE error is thrownHealthFitDataType.MINDFUL is 2419200 seconds. Beyond this limit, the NOT_AVAILABLE error is thrownBe sure to insert data into a free datetime interval. Whether the inserted pediod is:
When empty start and end datetime are passed, default values are:
Allow user to delete data in a time interval
delete(options: {type: string, start: Date, end: Date}): Promise<{succeeded: boolean}>;
{type: success} : success if true is passed, otherwise false{type: function(err)}, called if something went wrong, err can be :
HealthFitDataType.ACTIVITY on iOS)HealthFitDataType.ACTIVITY dataHealthFitDataType.ACTIVITY data but it's a non sens. Activity represent the move in minutes, not the real exercice type...When plugin error occurs, promise is rejected with a string error code.
try {
await HealthFit.isAuthorized({
type: HealthFitDataType.STEP_COUNT,
mode: HealthFitAuthorizationType.READ
})
} catch (error) {
alert(`Error code: ${error}`);
}
Here are available error codes:
| Error codes | Meaning |
|---|---|
| HEALTH_FIT_NOT_AVAILABLE | Healthkit or Googlefit is not available on the device |
| MISSING_PLUGIN_PARAMETER | A required parameter is missing |
| BAD_PLUGIN_PARAMETER | Invalid parameter passed to the plugin (data type problem) |
| UNKNOWN_TYPE | The datatype parameter is not recognized (it is not part of HealthFitDataType) |
| AUTHORIZATION_NOT_DETERMINED | The authorization for a datatype is not determined. |
| PERMISSION_DENIED | Access or write permission to a datatype is denied |
| TECHNICAL_ERROR | Unrecognized and unanticipated error. Details are available in the logs |
| BAD_DATE_FORMAT | Wrong date format |
| BAD_END_DATE | The end date is earlier than the start date (when retrieving or inserting data) |
| NOT_AVAILABLE | Action not available (for example, add an activity on iOS) |
FAQs
Capacitor plugin that allows to communicate with Healthkit and Google fit
The npm package capacitor-health-fit receives a total of 21 weekly downloads. As such, capacitor-health-fit popularity was classified as not popular.
We found that capacitor-health-fit demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Research
/Security News
Another wave of Shai-Hulud campaign has hit npm with more than 500 packages and 700+ versions affected.

Product
Add real-time Socket webhook events to your workflows to automatically receive software supply chain alert changes in real time.

Security News
ENISA has become a CVE Program Root, giving the EU a central authority for coordinating vulnerability reporting, disclosure, and cross-border response.