Skip to content

feat: Add support for background access permission (READ_HEALTH_DATA_IN_BACKGROUND)#212

Merged
matinzd merged 4 commits intomatinzd:mainfrom
mikitu:main
Jun 12, 2025
Merged

feat: Add support for background access permission (READ_HEALTH_DATA_IN_BACKGROUND)#212
matinzd merged 4 commits intomatinzd:mainfrom
mikitu:main

Conversation

@mikitu
Copy link
Contributor

@mikitu mikitu commented Apr 15, 2025

This PR adds support for the Health Connect background access permission, allowing apps to read health data while running in the background.

Main changes:

  • Added support for PERMISSION_READ_HEALTH_DATA_IN_BACKGROUND permission
  • Enhanced permission handling in PermissionUtils to process background access permission requests
  • Included both background access permission and exercise route permission in getGrantedPermissions() results
  • Updated documentation with background access permission details and examples
  • Added background access permission handling to the example app

Additional improvements:

  • Refactored special permissions handling in mapPermissionResult()
  • Ensured consistent handling of both regular and special permissions

Usage example:
Request permissions:

requestPermission([
  {
    accessType: 'read',
    recordType: 'BackgroundAccessPermission',
  },
  {
    accessType: 'read',
    recordType: 'Steps',
  },
  {
    accessType: 'write',
    recordType: 'ExerciseRoute',
  }
]);

Example response from the example app:
Granted permissions:

{
  "permissions": [
    {"accessType": "read", "recordType": "CyclingPedalingCadence"},
    {"accessType": "write", "recordType": "CyclingPedalingCadence"},
    {"accessType": "read", "recordType": "ExerciseSession"},
    {"accessType": "write", "recordType": "ExerciseSession"},
    {"accessType": "read", "recordType": "StepsCadence"},
    {"accessType": "write", "recordType": "StepsCadence"},
    {"accessType": "read", "recordType": "Steps"},
    {"accessType": "write", "recordType": "Steps"},
    {"accessType": "write", "recordType": "ExerciseRoute"},
    {"accessType": "read", "recordType": "BackgroundAccessPermission"}
  ]
}

Check granted permissions:

getGrantedPermissions().then((permissions) => {
  const hasBackgroundAccess = permissions.some(
    (permission) =>
      permission.accessType === 'read' &&
      permission.recordType === 'BackgroundAccessPermission'
  );
  
  const hasExerciseRouteAccess = permissions.some(
    (permission) =>
      permission.accessType === 'write' &&
      permission.recordType === 'ExerciseRoute'
  );
});

Screenshot_20250416_004131_HealthConnect
Screenshot_20250416_004140_HealthConnect
Screenshot_20250416_004151_HealthConnect

@jnelder1
Copy link

Any update on this being merged, would love this feature for our project!

@brycegoh
Copy link

brycegoh commented Jun 8, 2025

Any updates on when this PR can be merged? @matinzd able to take a look when you are free? Thanks, appreciate it!

@mikitu
Copy link
Contributor Author

mikitu commented Jun 10, 2025

hi @matinzd, i fixed the conflicts. can you take a look ?

@brycegoh
Copy link

thanks everyone @mikitu @matinzd. Appreciate it a lot!

@matinzd matinzd merged commit 4ddb0da into matinzd:main Jun 12, 2025
3 checks passed
@premyslvlcek
Copy link

Hi, when can we expect a new release with this PR included? Thanks

@matinzd
Copy link
Owner

matinzd commented Jul 23, 2025

Hi @premyslvlcek

I need to do some testing before the actual release. You can try to fork and serve it in your own registry for now.

@premyslvlcek
Copy link

Hi @premyslvlcek

I need to do some testing before the actual release. You can try to fork and serve it in your own registry for now.

Okay, thanks for your quick response. I'll give it a try.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Type: feature request New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature Request: Allow asking for READ_HEALTH_DATA_IN_BACKGROUND permissions Background Delivery

5 participants

Comments