checkSamsungHealthDataAvailability method
Check if Samsung Health Data is available on the device.
Possible return values:
- notInstalled - Samsung Health is not installed. Ask user to install it.
- updateRequired - The version of Samsung Health is too old. Ask users to update it.
- disabled - The Samsung Health Data is installed but is disabled.
- notInitialized - Samsung Health has been installed but the user didn't perform an initial process, such as agreeing to the Terms and Conditions.
- errorOther - Samsung Health returned other error.
- installed - Samsung Health Data is available.
Implementation
Future<SamsungHealthAvailability> checkSamsungHealthDataAvailability() async {
if (!Platform.isAndroid) {
return SamsungHealthAvailability(
status: SamsungHealthAvailabilityStatus.notInstalled,
errorCode: 0,
message: 'Samsung Health Data is only available on Android',
);
}
final result = await NativeSDKBridgeV3.checkSamsungHealthDataAvailability(
connectionId: connectionId,
);
// print('Raw result from native bridge: "$result"');
if (result == null || result.isEmpty) {
// print('Result is null or empty, returning default availability');
return SamsungHealthAvailability(
status: SamsungHealthAvailabilityStatus.notInstalled,
errorCode: -1,
message: 'No response from native SDK',
);
}
try {
final jsonMap = jsonDecode(result);
// print('Decoded JSON: $jsonMap');
return SamsungHealthAvailability.fromJson(jsonMap);
} catch (e) {
// print('Error decoding JSON: $e');
return SamsungHealthAvailability(
status: SamsungHealthAvailabilityStatus.errorOther,
errorCode: -1,
message: 'Failed to decode response: $e',
);
}
}