Samsung Health Data is available on Android devices only!

Step 1: Create Spike connection

If you already set up Android Health Connect or Apple HealthKit integration in your app, you should skip this step and use the same SpikeSDK connection object.

To set up the Spike SDK create SpikeConnectionV3 instance with your Spike application id, application user id and signature unique to each of your apllication users (more on generating signatures here):

import Spike from 'react-native-spike-sdk';

const connection = await Spike.createConnectionAPIv3({
    applicationId: 1000,
    signature: "signature",
    endUserId: "user-id"
});

Step 2: Ask user for permissions

If you want to read data from Samsung Health, you have to ensure user gives your app permissions. First, you have to check if Samsung Health is available on users phone using checkSamsungHealthDataAvailability method:

val availability = spikeConnection.checkSamsungHealthDataAvailability()

where

interface SamsungHealthDataAvailability {
  status: SamsungHealthDataAvailabilityStatus;
  errorCode: number;
  message: string;
} 

enum SamsungHealthDataAvailabilityStatus {
  /**
   * Samsung Health is not installed. Ask user to install it.
   */
  notInstalled = "NOT_INSTALLED",

  /**
   * The version of Samsung Health is too old. Ask users to update it.
   */
  updateRequired = "UPDATE_REQUIRED",

  /**
   * The Samsung Health Data is installed but is disabled.
   */
  disabled = "DISABLED",

  /**
   * Samsung Health has been installed but the user didn't perform an initial process, such as
   * agreeing to the Terms and Conditions.
   */
  notInitialized = "NOT_INITIALIZED",

  /**
   * Samsung Health returned other error.
   */
  errorOther = "ERROR_OTHER",

  /**
   * Samsung Health Data is available.
   */
  installed = "INSTALLED",
} 

If Samsung Health is installed, you can ask user for permissions using requestPermissions method:

// Samsung Health integration has to be enabled in SpikeSDK connection before 
// using further methods for reading data or managing permissions:
spikeConnection.enableSamsungHealthDataIntegration()

spikeConnection.requestPermissionsFromSamsungHealthData(
    statisticsTypes = setOf(StatisticsType.STEPS, StatisticsType.DISTANCE_TOTAL)
)

Please note that users might only grant partial permissions. In such cases, it’s up to you to decide whether your app can function effectively with limited access. The SpikeSDK itself will still operate even without full permissions; however, it may result in no data being returned in certain scenarios.

You can now use StatisticsFilter(providers = listOf(Provider.SAMSUNG_HEALTH_DATA)) to specifically retrieve data from Samsung Health. Alternatively, you can omit the providers parameter entirely and allow Spike to choose the most suitable data source based on your request.

Step 3: Get data

Reading data is the same as for Android Health Connect. The only difference is that you may want to filter results by Provider.SAMSUNG_HEALTH_DATA to get only Samsung Health data:

StatisticsFilter(providers = [Provider.SAMSUNG_HEALTH_DATA])

Background delivery

Samsung Health data can be delivered in background the same way as Apple HealthKit or Android Health Connect. If you want to use background delivery to get Samsung Health data, you have to enable Samsung Health Data integration first:

spikeConnection.enableSamsungHealthDataIntegration()

After enabling Samsung Health Data integration, you can use background delivery normally. See Background Delivery section for more details.