react-native-health-connect: error: method setPermissionDelegate in class HealthConnectPermissionDelegate cannot be applied to given types

This is the error am getting

android/app/src/main/java/com/ziva/MainActivity.java:26: error: method setPermissionDelegate in class HealthConnectPermissionDelegate cannot be applied to given types;
    HealthConnectPermissionDelegate.setPermissionDelegate(this);
                                   ^
  required: ReactActivity,String
  found: MainActivity
  reason: actual and formal argument lists differ in length
1 error

FAILURE: Build completed with 2 failures.

as per installation guide I have made change on my MainActivity.java as my project is on java

on import part I added import dev.matinzd.healthconnect.permissions.HealthConnectPermissionDelegate;

and replaced onCreate() method with this

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    HealthConnectPermissionDelegate.setPermissionDelegate(this);
  }

and also on my android studio I can see an error on same thing Non-static method 'setPermissionDelegate(error.NonExistentClass, java.lang.String)' cannot be referenced from a static context

Environment:

  • “react-native-health-connect”: “2.0.1”,
  • “react-native”: “0.69.5”

About this issue

  • Original URL
  • State: closed
  • Created 3 months ago
  • Comments: 22 (5 by maintainers)

Most upvoted comments

In Java I call the setPermissionDelegate method like this: HealthConnectPermissionDelegate.INSTANCE.setPermissionDelegate(this, "package.name");

On Android 14 it works fine but for others it crushes

Please follow the documentation. Use RN 71 and above with latest patch. Follow all the docs and see if it works. I’ve followed all the steps outlined in the library documentation, ensuring that I have the latest versions of React, React Native, and Health Connect. Additionally, I’ve set up my manifest file, MainActivity, and permission rationale file according to the examples provided in the library’s GitHub repository.

However, the app functions correctly on Android version 14 . When requesting permission using the Health Connect permission API , the permission modal appears as expected. However, upon requesting permission on lower Android versions, the API returns an empty error response. This occurs even after downloading the Health Connect app.

Manifest file : Screenshot from 2024-05-03 12-01-09

Main Activity file : Screenshot from 2024-05-03 12-01-30

Permission Rational file : Screenshot from 2024-05-03 12-01-38

Package.json file : Screenshot from 2024-05-03 12-02-20

Android 14 Execution and response : Screenshot from 2024-05-03 11-30-51 Screenshot from 2024-05-03 11-31-07

Android 13 Execution and response : Screenshot from 2024-05-03 11-43-53 Screenshot from 2024-05-03 11-59-49

@matinzd My application has the following setup:

react-native: 0.71.18 react-native-health-connect: ^2.0.1 buildToolsVersion: 34.0.0 minSdkVersion: 26 compileSdkVersion: 34 targetSdkVersion: 34 kotlinVersion: 1.8.0 The app works fine on Android 14, but it’s not functioning on versions lower than 14, such as Android 12 or 11. Specifically, the requestPermission() method isn’t being called on those lower versions.

Working in 14 version and for other version crash.

The method does not work. It does not prompt for permission on version 13, but it works fine on version 14.

version: react-native-health-connect@2.0.1

import { requestPermission } from ‘react-native-health-connect’; const grantedPermissions = await requestPermission([ ‘ActiveCaloriesBurned’, ‘BasalBodyTemperature’, ‘BasalMetabolicRate’, ]);