PermissionController


public interface PermissionController

Known direct subclasses
FakePermissionController

A fake PermissionController that enables full control of permissions in tests for a HealthConnectClient.


Interface for operations related to permissions.

Summary

Public methods

default static final @NonNull ActivityResultContract<@NonNull Set<@NonNull String>, @NonNull Set<@NonNull String>>

Creates an ActivityResultContract to request Health permissions.

abstract @NonNull Set<@NonNull String>

Returns a set of all health permissions granted by the user to the calling app.

abstract void

Revokes all previously granted HealthPermission by the user to the calling app.

Public methods

createRequestPermissionResultContract

Added in 1.1.0-alpha10
default static final @NonNull ActivityResultContract<@NonNull Set<@NonNull String>, @NonNull Set<@NonNull String>> createRequestPermissionResultContract(
    @NonNull String providerPackageName
)

Creates an ActivityResultContract to request Health permissions.

import androidx.health.connect.client.PermissionController
import androidx.health.connect.client.permission.HealthPermission
import androidx.health.connect.client.records.StepsRecord

val requestPermission =
    activity.registerForActivityResult(
        PermissionController.createRequestPermissionResultContract()
    ) { grantedPermissions: Set<String> ->
        if (
            grantedPermissions.contains(HealthPermission.getReadPermission(StepsRecord::class))
        ) {
            // Read or process steps related health records.
        } else {
            // user denied permission
        }
    }
requestPermission.launch(setOf(HealthPermission.getReadPermission(StepsRecord::class)))
Parameters
@NonNull String providerPackageName

Optional provider package name to request health permissions from.

getGrantedPermissions

abstract @NonNull Set<@NonNull StringgetGrantedPermissions()

Returns a set of all health permissions granted by the user to the calling app.

import androidx.health.connect.client.permission.HealthPermission
import androidx.health.connect.client.records.StepsRecord

val grantedPermissions = permissionController.getGrantedPermissions()

if (grantedPermissions.contains(HealthPermission.getReadPermission(StepsRecord::class))) {
    // Read or process steps related health records.
} else {
    // user denied permission
}
Returns
@NonNull Set<@NonNull String>

set of granted permissions.

Throws
android.os.RemoteException

For any IPC transportation failures.

java.io.IOException

For any disk I/O issues.

kotlin.IllegalStateException

If service is not available.

revokeAllPermissions

Added in 1.1.0-alpha10
abstract void revokeAllPermissions()

Revokes all previously granted HealthPermission by the user to the calling app.

Throws
android.os.RemoteException

For any IPC transportation failures.

java.io.IOException

For any disk I/O issues.

kotlin.IllegalStateException

If service is not available.