Search code examples
androidgoogle-fit-api

Runtime Error: This app can't access Health Connect


I'm a developer on a fitness app that is trying to integrate with Health Connect, I followed all the API specs and got it working on my test phones, and if I install it on my phone via the Internal Testing channel on Google Play. It works great. However, when we distributed the app to our testers via Closed Testing channel on Google Play, they get the following message:

This app can't access Health Connect Error they see on the phone

They updated the app, as instructed. They all have Health Connect (Beta) installed, but when trying to ask for permissions inside our app, they get the error.

What other permissions do published apps need in order to make this work? Thank you,

The way app accesses the client:

private val requestPermissions =
    registerForActivityResult(requestPermissionActivityContract) { granted ->
        updatePermissionsList(granted)
    }
...
viewLifecycleOwner.lifecycleScope.launchWhenStarted {
    val granted =
        HealthConnectClient.getOrCreate(requireContext())
            .permissionController
            .getGrantedPermissions(CoPilotHealthConnectApi.PERMISSIONS)
    if (granted.containsAll(CoPilotHealthConnectApi.PERMISSIONS)) {
        val intent =
            requireContext()
                .packageManager
                .getLaunchIntentForPackage("com.google.android.apps.healthdata")
        context?.startActivity(intent)
    } else {
        requestPermissions.launch(CoPilotHealthConnectApi.PERMISSIONS)
    }
...

Build file:

   minSdk 28
   targetSdk 33

Tried:

  1. Worked well on debug builds
  2. Worked on my devices when distributed via Internal testing on Play Store.
  3. Did not work when the clients on Closed testing channel tried to use it. They get the error dialog attached above.

Expecting:

  1. Same behavior for all users across all channels/devices.

Solution

  • Apps currently need to be allowlisted to get access to Health Connect. You can follow the process outlined at: https://developer.android.com/guide/health-and-fitness/health-connect/frequently-asked-questions#q_how_do_i_request_access_to_readwrite_data_types