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:
| Status | Description | What to do |
|---|---|---|
| installed | Samsung Health is installed and ready to be used. | Proceed to check permissions |
| notInstalled | Samsung Health is not installed. | Prompt the user to install Samsung Health. |
| outdated | The version of Samsung Health is too old. | Prompt the user to update Samsung Health. |
| disabled | Samsung Health is disabled. | Prompt the user to enable Samsung Health. |
| notReady | The 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
requestSamsungHealthPermissionsUpdatesstream.
// 1.- Create a stream subscription
StreamSubscription<SamsungHealthPermissionsSummary>? 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
});
}
Optimization permissions
Some users want to have as much battery life as possible, so they have power saving mode always active, also some phone manufactures add their own energy restriction on top of Android's, these restrictions are mostly enabled by default and depending on the device will add a delay to our background services; Background Sync or even stop them completely.
We have added mutiple optimization paths you can follow:
The following are optional permissions, you can use the Background Sync component without these permission, however we recommend to add a button to ask this permission in a support page of your application so users can grant it if they are experiencing interruptions with the service.
Alarm permissions
The SDK uses the android.permission.SCHEDULE_EXACT_ALARM (pre-included in SDK's manifest) to improve the lifetime of
Background Services in battery constrained scenarios.
To check permissions call checkExactAlarmPermissions:
RookSamsung.checkExactAlarmPermissions().then((hasAlarmPermissions) {
// Success
}).catchError((error) {
// Handle error
});
To request permissions call requestExactAlarmPermissions:
RookSamsung.requestExactAlarmPermissions().then((requestPermissionsStatus) {
switch (requestPermissionsStatus) {
case RequestPermissionsStatus.alreadyGranted:
// Permissions already granted.
case RequestPermissionsStatus.requestSent:
// Because this is a special app access permission,
// there is no callback the recommended pattern is to call checkExactAlarmPermissions again.
}
}).catchError((error) {
// Handle error
});
On API 26–30 exact alarms are unrestricted so checkExactAlarmPermissions/requestExactAlarmPermissions will always
return true/RequestPermissionsStatus.requestSent.
Battery optimizations
To check if battery optimizations are disabled call checkBatteryOptimizationsDisabled:
RookSamsung.checkBatteryOptimizationsDisabled().then((batteryOptimizationsDisabled) {
// Success
}).catchError((error) {
// Handle error
});
To request disabling battery optimizations call requestDisableBatteryOptimizations:
RookSamsung.requestDisableBatteryOptimizations().then((requestPermissionsStatus) {
switch (requestPermissionsStatus) {
case RequestPermissionsStatus.alreadyGranted:
// Battery optimizations are already disabled
case RequestPermissionsStatus.requestSent:
// Because this is a special app access permission,
// there is no callback the recommended pattern is to call checkBatteryOptimizationsDisabled again.
}
}).catchError((error) {
// Handle error
});
Auto start
Brands like OPPO, One Plus and Xiaomi implement a custom Auto Start restriction that limits app's background execution.
You can check if the current device belongs to an OEM that enforces this restriction with requiresOemAutoStartSetup:
RookSamsung.requiresOemAutoStartSetup().then((hasAutoStartRestriction) {
// Success
}).catchError((error) {
// Handle error
});
Detection works by probing whether any known OEM settings screen resolves on the device. A true result means the OEM
management system exists it does not mean auto start is currently blocked for this specific app. Use this to decide
whether to prompt the user to open the OEM setup screen.
To open the brand-specific settings screen call openOemAutoStartSetup:
RookSamsung.openOemAutoStartSetup().then((requestPermissionsStatus) {
switch (requestPermissionsStatus) {
case RequestPermissionsStatus.alreadyGranted:
// The device has no OEM screen
case RequestPermissionsStatus.requestSent:
// Because this is a brand specific there is no way to know the user's choice.
}
}).catchError((error) {
// Handle error
});