Skip to main content

Usage: Availability and permissions

Check permissions and Samsung Health app availability.

Check availability

Before proceeding further, ensure that the Samsung Health app is installed and ready to be used, call checkSamsungHealthAvailability:

StatusDescriptionWhat to do
installedSamsung Health is installed and ready to be used.Proceed to check permissions
notInstalledSamsung Health is not installed.Prompt the user to install Samsung Health.
outdatedThe version of Samsung Health is too old.Prompt the user to update Samsung Health.
disabledSamsung Health is disabled.Prompt the user to enable Samsung Health.
notReadyThe user didn't perform an initial process, such as agreeing to the Terms and Conditions.Prompt the user to open and complete the onboarding process of Samsung Health.
void checkAvailability() {
RookSamsung.checkSamsungHealthAvailability().then((availability) {
// Success
}).catchError((exception) {
// Handle error
});
}

Samsung Health permissions

These are permissions used to extract data, each Samsung Health data type is subject to a different permission, below you can see the list of permissions ROOK needs:

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

Check permissions

To check permissions call checkSamsungHealthPermissions:

void checkPermissions() {
RookSamsung.checkSamsungHealthPermissions(samsungPermissions).then((permissionsGranted) {
// Update your UI
}).catchError((exception) {
// Handle error
});
}

The previous function will check for all permissions, to check if at least one permission is granted, call checkSamsungHealthPermissionsPartially:

void checkPermissionsPartially() {
RookSamsung.checkSamsungHealthPermissionsPartially(samsungPermissions).then((permissionsPartiallyGranted) {
// Update your UI
}).catchError((error) {
// Handle error
});
}

Request permissions

To request permissions call requestSamsungHealthPermissions:

void requestPermissions() {
RookSamsung.requestSamsungHealthPermissions(samsungPermissions).then((requestPermissionsStatus) {
if (requestPermissionsStatus == RequestPermissionsStatus.alreadyGranted) {
// Permissions already granted, update your UI
} else {
// Wait for result in stream
}
}).catchError((error) {
// Handle error
});
}

This function will return a RequestPermissionsStatus with 2 possible values:

  • alreadyGranted: The permissions are already granted thus no request was sent.
  • requestSent: The permissions request was sent, and you can get notified if the permissions were granted or denied using the requestSamsungHealthPermissionsUpdates stream.
// 1.- Create a stream subscription
StreamSubscription<bool>? streamSubscription;

// 2.- Listen to stream
streamSubscription = RookSamsung.requestSamsungHealthPermissionsUpdates.listen((permissionsSummary) {
// Updated your UI
});

// 3.- Request permissions
RookSamsung.requestSamsungHealthPermissions().then((requestPermissionsStatus) {
if (requestPermissionsStatus == RequestPermissionsStatus.alreadyGranted) {
// Permissions already granted, update your UI
} else {
// Wait for result in stream
}
}).catchError((error) {
// Handle error
});

// 4.- Stop listening to the stream
streamSubscription?.cancel();

Customizing permissions

The requestSamsungHealthPermissions, checkSamsungHealthPermissions and checkSamsungHealthPermissionsPartially functions accept a list of SamsungHealthPermission so you can only request/check the permissions your app truly needs:

void requestPermissions() {
final samsungPermissions = [
SamsungHealthPermission.activitySummary,
SamsungHealthPermission.bodyComposition,
SamsungHealthPermission.exercise,
SamsungHealthPermission.exerciseLocation,
SamsungHealthPermission.heartRate,
SamsungHealthPermission.sleep,
SamsungHealthPermission.steps,
];

RookSamsung.requestSamsungHealthPermissions(samsungPermissions).then((requestPermissionsStatus) {
// Success
}).catchError((error) {
// Handle error
});
}