Menu

 

Cordova

Cordova plugin for integrating WeFitter and Samsung Health into your app

Installation

cordova plugin add https://github.com/wefitter/cordova-plugin-wefitter-samsung.git#v0.5.4

 

Usage

Add the following code inside onDeviceReady in www/js/index.js:

See wefittersamsung.js for all available functions.

Show code example
Hide code example
// 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 `wefittersamsung.disconnect()` is also useful.
      wefittersamsung.isConnected((connected) => {
        if (!connected) wefittersamsung.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.reason);

  // `forUser` boolean indicates the error requires user interaction
  // `reason` can be checked to override specific messages
  if (error.forUser) {
    let message = error.reason;
    switch (error.reason) {
      case "Please install Samsung Health":
        // message = '' override for custom message
        break;
      case "Please update Samsung Health":
        // message = '' override for custom message
        break;
      case "Please enable Samsung Health":
        // message = '' override for custom message
        break;
      case "Please agree to Samsung Health policy":
        // message = '' override for custom message
        break;
      case "Please unlock Samsung Health":
        // message = '' override for custom message
        break;
      case "Please make Samsung Health available":
        // message = '' override for custom message
        break;
      case "Connection with Samsung Health is not available":
        // message = '' override for custom message
        break;
      case "At least one permission should be accepted":
        // message = '' override for custom message
        break;
    }
    navigator.notification.alert(message, () => {
      // `tryToResolveError` will guide the user on fixing certain errors
      // for example:
      // - link to the app store to install or update Samsung Health
      // - open Samsung Health to accept privacy policy
      // - open Settings when Samsung Health needs to be enabled
      wefittersamsung.tryToResolveError(error.reason);
    });
  }
};

// create config
const config = {
  token: "YOUR_TOKEN", // required
  apiUrl: "YOUR_API_URL", // required, the url should be base without `v1.3/ingest/` as the library will append this. For example: `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 wefittersamsung
wefittersamsung.configure(config, success, failure);

Thank you for reaching out!

We will be in touch with you soon. WeFitter team.

You are subscribed!

You will soon receive our newsletter!
WeFitter team.