Skip to main content

Getting started: Android configuration

Prepare your project for Samsung Health.

Android configuration

In your build.gradle (app) set your min and target sdk version like below:

minSdk 26
targetSdk 35

Obfuscation

If you are using obfuscation consider the following:

In your gradle.properties (Project level) add the following to disable R8 full mode:

android.enableR8.fullMode=false

If you want to enable full mode add the following rules to proguard-rules.pro:

# Keep generic signature of Call, Response (R8 full mode strips signatures from non-kept items).
-keep,allowobfuscation,allowshrinking interface retrofit2.Call
-keep,allowobfuscation,allowshrinking class retrofit2.Response

# With R8 full mode generic signatures are stripped for classes that are not
# kept. Suspend functions are wrapped in continuations where the type argument
# is used.
-keep,allowobfuscation,allowshrinking class kotlin.cor outines.Continuation

Request data access

During development, you can access Samsung Health data by enabling developer mode.

To have data access in the production environment, you must submit the Samsung's Partnership Request Form.

Please submit partner request before your app distribution. Your app's package name and signature (SHA-256) will be registered in the Samsung Health's system after an approval.

Ensure that the correct app signature and package name is registered. If your published app signature differs from what you have provided, your app will not have access to Samsung's data.

You will see a section like this, select only the data types under the "Read" section:

Samsung Health permissions

This SDK uses the following data types, however you don't need to declare all of them if you don't use it.

  • ACTIVITY_SUMMARY
  • BLOOD_GLUCOSE
  • BLOOD_OXYGEN
  • BLOOD_PRESSURE
  • BODY_COMPOSITION
  • EXERCISE
  • EXERCISE_LOCATION
  • FLOORS_CLIMBED
  • HEART_RATE
  • NUTRITION
  • SLEEP
  • STEPS
  • WATER_INTAKE
warning

If you exclude a data type of the previous list DO NOT use it in the permissions functions (check/request).

RookSamsung class

All SDK functions are located in the RookSamsung, you need to create an instance to use them, we recommend using the singleton pattern with a ServiceLocator or with dependency injection. The following example uses the Hilt dependency injection library:

<!--AndroidManifest.xml-->
<application
android:name=".RookSamsungApplication">
</application>
@HiltAndroidApp
class RookSamsungApplication : Application() {
}

@InstallIn(SingletonComponent::class)
@Module
object RookModule {
@Provides
@Singleton
fun provideRookSamsung(@ApplicationContext context: Context): RookSamsung {
return RookSamsung(context)
}
}
tip

RookSamsungObject is an alternative to the RookSamsung class that does not require an instance, however you'll need to provide a context with every function call:

val configuration = SHConfiguration(clientUUID, secretKey, environment)

// RookSamsung
val rookSamsung = RookSamsung(applicationContext)
rookSamsung.initRook(configuration)

// RookSamsungObject
RookSamsungObject.initRook(applicationContext, configuration)

Secure storage (optional)

This SDK saves sensitive information like current logged user in a password protected storage, you can specify a file name (without extension) and the password used to access it with two meta-data tags in your manifest:

info

This configuration is completely optional if you don't provide the two following tags the SDK will use a default file name and auto-generate a new password every time your app is installed or it's data is deleted.


<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<application>

<!--
PLEASE NOTE THAT BOTH TAGS ARE REQUIRED

IF YOU EVER LOSE THE PASSWORD THE SDK WILL BECOME UNABLE TO PERFORM ITS FUNCTIONS
YOU CAN CHANGE THE NAME OF THE STORAGE TO FIX IT, BUT ALL PREVIOUS DATA WILL BE LOST.
-->

<meta-data
android:name="io.tryrook.samsung.security.storage.FILE_NAME"
android:value="secure_storage"/>

<meta-data
android:name="io.tryrook.samsung.security.storage.PASSWORD"
android:value="my_super_secret_password"/>
</application>
</manifest>