Permission request for Samsung SDK not working for Heart Rate

154 views Asked by At

I´ve downloaded the SimpleHealth sample project from the Samsung Developer site. Link: https://developer.samsung.com/health/android/sample/simple-health.html

In the sample app StepCount permission is requested, which works:

    private void requestPermission() {
    PermissionKey permKey = new PermissionKey(StepCount.HEALTH_DATA_TYPE, PermissionType.READ);
    HealthPermissionManager pmsManager = new HealthPermissionManager(mStore);


    try {
        // Show user permission UI for allowing user to change options
        pmsManager.requestPermissions(Collections.singleton(permKey), MainActivity.this)
            .setResultListener(result -> {
                Log.d(APP_TAG, "Permission callback is received.");
                Map<PermissionKey, Boolean> resultMap = result.getResultMap();

                if (resultMap.containsValue(Boolean.FALSE)) {
                    updateHeartRateView("");
                    showPermissionAlarmDialog();
                } else {
                    // Get the current heart rate and display it
                    hrReporter.start();
                }
            });
    } catch (Exception e) {
        Log.e(APP_TAG, "Permission setting fails.", e);
    }
}

The following prompt opens where I can toggle all permissions and step count works:

Prompt1

However, when I change the code to request HeartRate data:

    private void requestPermission() {
    PermissionKey permKey = new PermissionKey(HeartRate.HEALTH_DATA_TYPE, PermissionType.READ);
    HealthPermissionManager pmsManager = new HealthPermissionManager(mStore);


    try {
        // Show user permission UI for allowing user to change options
        pmsManager.requestPermissions(Collections.singleton(permKey), MainActivity.this)
            .setResultListener(result -> {
                Log.d(APP_TAG, "Permission callback is received.");
                Map<PermissionKey, Boolean> resultMap = result.getResultMap();

                if (resultMap.containsValue(Boolean.FALSE)) {
                    updateHeartRateView("");
                    showPermissionAlarmDialog();
                } else {
                    // Get the current heart rate and display it
                    hrReporter.start();
                }
            });
    } catch (Exception e) {
        Log.e(APP_TAG, "Permission setting fails.", e);
    }
}

The following prompt opens but all permission cannot be toggled:

Prompt2

AndroidManifest:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.samsung.android.simplehealth"
android:versionCode="1"
android:versionName="1.0">

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.BODY_SENSORS" />
<uses-permission android:name="com.samsung.android.health.permission.read" />
<uses-permission android:name="android.permission.ACTIVITY_RECOGNITION" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />

<queries>
    <package android:name="com.sec.android.app.shealth" />
</queries>

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme">

    <meta-data android:name="com.samsung.android.health.permission.read"
        android:value="com.samsung.health.heart_rate" />
    <activity
        android:name="com.samsung.android.simplehealth.MainActivity"
        android:label="@string/app_name"
        android:exported="true"
        >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>

Why does StepCount work in the sample application but Heart Rate does not?

0

There are 0 answers