Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

error: method setPermissionDelegate in class HealthConnectPermissionDelegate cannot be applied to given types #81

Closed
NikhilPacewisdom opened this issue Apr 4, 2024 · 24 comments · Fixed by #110
Assignees

Comments

@NikhilPacewisdom
Copy link

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"
@vladposhenko
Copy link

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

@richardReitz
Copy link

Same issue

@StriderHND
Copy link

same issue also with java project

@NikhilPacewisdom
Copy link
Author

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

This worked for me but as mentioned only for Android14

@StriderHND
Copy link

StriderHND commented Apr 17, 2024

Made the suggested change to test but now getting these errors

Screenshot 2024-04-17 at 18 59 10

Environment:

"react-native-health-connect": "2.0.1",
"react-native": "0.68.5"

@mujeeb98
Copy link

mujeeb98 commented Apr 19, 2024

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: [email protected]

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

@matinzd
Copy link
Owner

matinzd commented Apr 19, 2024

I'll investigate this after I am back from the vacation.

@Satyam-shm
Copy link

In Android 14, it works fine, but it doesn’t work on versions lower than 14. I’ve granted all permissions for Android Health Connect, but the app doesn’t read data from Health Connect on these older versions. However, it works without issues in Android 14. The requestPermission method isn’t working on versions lower than 14. Could anyone help me figure out how to fix this?
import { requestPermission } from ‘react-native-health-connect’;
const accessPermissions = await requestPermission([{accessType: ‘read’, recordType:“Height”},{accessType: ‘read’, recordType:“Steps”},………….);

@darshan2911
Copy link

darshan2911 commented Apr 23, 2024

in MainActivity.java - changing this -
HealthConnectPermissionDelegate.setPermissionDelegate(this);
as - HealthConnectPermissionDelegate.INSTANCE.setPermissionDelegate(this, "com.google.android.apps.healthdata");
will work fine in lower versions of Android, but having problem in Android 14 - requestPermission method is not returning anymore.

using React native - 0.71.7,
other versions -
buildToolsVersion = "34.0.0"
minSdkVersion = 26
compileSdkVersion = 34
targetSdkVersion = 33
supportLibVersion = "28.0.0"
supportVersion = "28.0.0"
kotlinVersion = "1.8.0"
node version - 14.17.3

@mujeeb98
Copy link

mujeeb98 commented Apr 23, 2024

@darshan2911, add the following code to your Android Manifest file:

 <activity
            android:name=".PermissionsRationaleActivity"
            android:exported="true">
            <intent-filter>
                <action android:name="androidx.health.ACTION_SHOW_PERMISSIONS_RATIONALE" />
            </intent-filter>
        </activity>
        <!-- For versions starting with Android 14 -->
        <activity-alias
            android:name="ViewPermissionUsageActivity"
            android:exported="true"
            android:targetActivity=".PermissionsRationaleActivity"
            android:permission="android.permission.START_VIEW_PERMISSION_USAGE">
            <intent-filter>
                <action android:name="android.intent.action.VIEW_PERMISSION_USAGE" />
                <category android:name="android.intent.category.HEALTH_PERMISSIONS" />
            </intent-filter>
        </activity-alias>

Additionally, create a new file called PermissionsRationaleActivity.java in the java folder with the following content:

package [your app package name];
import android.webkit.WebResourceRequest;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import androidx.appcompat.app.AppCompatActivity;

public class PermissionsRationaleActivity extends AppCompatActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        WebView webView = new WebView(this);
        webView.setWebViewClient(new WebViewClient() {
            @Override
            public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
                return false;
            }
        });

        webView.loadUrl("https://developer.android.com/health-and-fitness/guides/health-connect/develop/get-started");

        setContentView(webView);
    }
}

PermissionsRationaleActivity File:
Screenshot 2024-04-23 at 12 56 42 PM

MainActivity File:
Screenshot 2024-04-23 at 1 04 10 PM

Use this version of Health Connect: [email protected]

It works fine on Android 14, but not on lower versions. I have already mentioned the issue here: #81 (comment)

@darshan2911
Copy link

@mujeeb98, still not working in Android 14 - i am having pop up of permission in every version of Android but response after Allowing permission for requestPermission method i am not getting in Android 14, getting in lower versions

@darshan2911
Copy link

@ismaelaarab i guess you are working with expo - i am working with react native CLI so i need some other solution.

@matinzd
Copy link
Owner

matinzd commented Apr 23, 2024

Hey everyone,

Can someone clarify of what's happening here? Is the solution in documentation doesn't work on Android 14 or on Android 13 or lower?

@matinzd matinzd self-assigned this Apr 23, 2024
@darshan2911
Copy link

Hey everyone,

Can someone clarify of what's happening here? Is the solution in documentation doesn't work on Android 14 or on Android 13 or lower?,

Solution in Documentation working fine in newer react native version for all the Android versions, i am currently having problem in React native - 0.71.7,
other versions -
buildToolsVersion = "34.0.0"
minSdkVersion = 26
compileSdkVersion = 34
targetSdkVersion = 33
supportLibVersion = "28.0.0"
supportVersion = "28.0.0"
kotlinVersion = "1.8.0"
node version - 14.17.3

@matinzd
Copy link
Owner

matinzd commented Apr 23, 2024

Based on this PR that is picked for RN 71, you should be able to use it without any problems.

https://github.com/facebook/react-native/releases/tag/v0.71.16

As mentioned here you need to have the latest patch of RN 71 and above:
https://github.com/matinzd/react-native-health-connect/releases/tag/v2.0.0

So please upgrade your React Native version to latest patch version of 0.71.

@matinzd matinzd closed this as completed Apr 23, 2024
@mujeeb98
Copy link

@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.

@Satyam-shm
Copy link

@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.

Also,my app is not functioning on lower versions, but it works fine on Android 14. The requestPermission method returns an empty array when called. All my libraries are up to date, yet the issue persists.

@matinzd
Copy link
Owner

matinzd commented May 1, 2024

Please follow the documentation. Use RN 71 and above with latest patch. Follow all the docs and see if it works.

@Satyam-shm
Copy link

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

@sudo-saquib
Copy link

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

Yeah this isn't working on Android 13

@matinzd
Copy link
Owner

matinzd commented May 3, 2024

Can you share the your AndroidManifest.xml here? @Satyam-shm @sudo-saquib

@Satyam-shm
Copy link

Satyam-shm commented May 3, 2024

@matinzd here is the code :

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.CAMERA"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" android:maxSdkVersion="28" />
<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.ACTION_MANAGE_ALL_FILES_ACCESS_PERMISSION"/>
<uses-permission android:name="android.permission.READ_MEDIA_IMAGES" />
<uses-permission android:name="android.permission.READ_MEDIA_VIDEO" />
<uses-permission android:name="android.permission.READ_MEDIA_VISUAL_USER_SELECTED" />
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
<uses-permission android:name="android.permission.RECORD_AUDIO"/>
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
<uses-permission android:name="android.permission.MICROPHONE" />
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
<uses-permission android:name="android.hardware.camera" android:required="true" />
<uses-permission android:name="android.hardware.camera.autofocus" android:required="false" />
<uses-permission android:name="android.hardware.microphone" android:required="true" />
<uses-permission android:name="android.permission.health.READ_BASAL_METABOLIC_RATE"/>
<uses-permission android:name="android.permission.health.READ_ACTIVE_CALORIES_BURNED"/>
<uses-permission android:name="android.permission.health.READ_BLOOD_GLUCOSE"/>
<uses-permission android:name="android.permission.health.READ_BLOOD_PRESSURE"/>
<uses-permission android:name="android.permission.health.READ_BODY_FAT"/>
<uses-permission android:name="android.permission.health.READ_BONE_MASS"/>
<uses-permission android:name="android.permission.health.READ_HYDRATION"/>
<uses-permission android:name="android.permission.health.READ_NUTRITION"/>
<uses-permission android:name="android.permission.health.READ_RESPIRATORY_RATE"/>
<uses-permission android:name="android.permission.health.READ_OXYGEN_SATURATION"/>
<uses-permission android:name="android.permission.health.READ_RESTING_HEART_RATE"/>
<uses-permission android:name="android.permission.health.READ_POWER"/>
<uses-permission android:name="android.permission.health.READ_WEIGHT"/>
<uses-permission android:name="android.permission.health.READ_HEIGHT"/>
<uses-permission android:name="android.permission.health.READ_LEAN_BODY_MASS"/>
<uses-permission android:name="android.permission.health.READ_SEXUAL_ACTIVITY"/>
<uses-permission android:name="android.permission.health.READ_SLEEP"/>
<uses-permission android:name="android.permission.health.READ_SPEED"/>
<uses-permission android:name="android.permission.health.READ_TOTAL_CALORIES_BURNED"/>
<uses-permission android:name="android.permission.health.READ_VO2_MAX"/>
<uses-permission android:name="android.permission.health.READ_WHEELCHAIR_PUSHES"/>

<!-- Application Declaration -->
<application
    android:largeHeap="true"
    android:name=".MainApplication"
    android:label="@string/app_name"
    android:icon="@mipmap/ic_launcher"
    android:roundIcon="@mipmap/ic_launcher_round"
    android:allowBackup="false"
    android:theme="@style/AppTheme">

    <!-- Main Activity -->
    <activity
        android:name=".MainActivity"
        android:label="@string/app_name"
        android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|screenSize|smallestScreenSize|uiMode"
        android:launchMode="singleTask"
        android:screenOrientation="portrait"
        android:windowSoftInputMode="adjustResize"
        android:exported="true">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

   <!-- For supported versions through Android 13, create an activity to show the rationale
       of Health Connect permissions once users click the privacy policy link. -->
<activity
  android:name=".PermissionsRationaleActivity"
  android:exported="true">
  <intent-filter>
    <action android:name="androidx.health.ACTION_SHOW_PERMISSIONS_RATIONALE" />
  </intent-filter>
</activity>

<!-- For versions starting Android 14, create an activity alias to show the rationale
     of Health Connect permissions once users click the privacy policy link. -->
<activity-alias
  android:name="ViewPermissionUsageActivity"
  android:exported="true"
  android:targetActivity=".PermissionsRationaleActivity"
  android:permission="android.permission.START_VIEW_PERMISSION_USAGE">
  <intent-filter>
    <action android:name="android.intent.action.VIEW_PERMISSION_USAGE" />
    <category android:name="android.intent.category.HEALTH_PERMISSIONS" />
  </intent-filter>
</activity-alias>
  </application>
  <queries>
<package android:name="com.google.android.apps.healthdata" />

@KapilSharma234
Copy link

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

Yes @Satyam-shm I am also following the library code but it is not working on Android 13 or lower devices. @matinzd Can you please help us out?

@milkmouth
Copy link

milkmouth commented Jun 24, 2024

Android 14 success Android 9 Failed on requestPermission

Logcat : 
FATAL EXCEPTION: DefaultDispatcher-worker-1
Process: com.app, PID: 23592
android.content.ActivityNotFoundException: No Activity found to handle Intent { act=androidx.health.ACTION_REQUEST_PERMISSIONS pkg=com.app (has extras) }
"react-native": "0.74.2",
"react-native-health-connect": "^2.0.3",
buildToolsVersion = "34.0.0"
minSdkVersion = 26
compileSdkVersion = 34
targetSdkVersion = 34
kotlinVersion = "1.8.0"

@matinzd matinzd linked a pull request Jun 29, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.