Cordova
Cordova plugin for integrating WeFitter and Health Connect into your app
Installation
Usage
Add the following code inside onDeviceReady
in www/js/index.js
:
See wefitterhealthconnect.js for all available functions.
// create success and failure handlers to receive status changes and errors
const success = (status) => {
switch (status) {
case "CONFIGURED":
console.log(status);
// enable connection if it hasn't already been enabled,
// or move this for example to a button press or toggle change
// and then `wefitterhealthconnect.disconnect()` is also useful.
wefitterhealthconnect.isConnected((connected) => {
if (!connected) wefitterhealthconnect.connect();
});
break;
case "NOT_CONFIGURED":
console.log(status);
break;
case "CONNECTED":
console.log(status);
break;
case "DISCONNECTED":
console.log(status);
break;
}
};
const failure = (error) => {
console.log(error);
};
// create config
const config = {
token: "YOUR_TOKEN", // required, WeFitter API profile bearer token
apiUrl: "YOUR_API_URL", // optional, only use if you want to use your backend as a proxy and forward all API calls to the WeFitter API. Default: `https://api.wefitter.com/api/`
startDate: "CUSTOM_START_DATE", // optional with format `yyyy-MM-dd`, by default data of the past 20 days will be uploaded
notificationTitle: "CUSTOM_TITLE", // optional
notificationText: "CUSTOM_TEXT", // optional
notificationIcon: "CUSTOM_ICON", // optional, e.g. `ic_notification` placed in either drawable, mipmap or raw
notificationChannelId: "CUSTOM_CHANNEL_ID", // optional
notificationChannelName: "CUSTOM_CHANNEL_NAME", // optional
};
// configure wefitterhealthconnect
wefitterhealthconnect.configure(config, success, failure);