requestPermission returns empty array (RN 0.73.6)
jakecurreri opened this issue · 5 comments
The requestPermission
method returns an empty array.
After initializing Health Connect and confirming the SDK is available, I request permissions along the lines of the core example:
if (!hasHealthConnect) {
console.error('Health Connect is not available');
return Promise.reject();
}
const isInitialized = await initialize();
if (!isInitialized) {
console.error('Failed to initialize Health Connect');
return Promise.reject();
}
const grantedPermissions = await requestPermission([
{accessType: 'read', recordType: 'ActiveCaloriesBurned'},
]);
console.log('Granted permissions:', grantedPermissions);
Which logs the empty array for permissions:
SDK is available
Granted permissions: []
All configurations are set according to the docs:
AndroidManifest.xml
<uses-permission android:name="android.permission.health.READ_ACTIVE_CALORIES_BURNED"/>
...
<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|screenSize|smallestScreenSize|uiMode"
android:launchMode="singleTask"
android:windowSoftInputMode="adjustResize"
android:exported="true">
...
<intent-filter>
<action android:name="androidx.health.ACTION_SHOW_PERMISSIONS_RATIONALE" />
</intent-filter>
</activity>
MainActivity.kt
import android.os.Bundle
// ...
import dev.matinzd.healthconnect.permissions.HealthConnectPermissionDelegate
//...
override fun onCreate(savedInstanceState: Bundle?) {
// react-native-screens override
super.onCreate(null);
HealthConnectPermissionDelegate.setPermissionDelegate(this)
}
//...
I have tested several error resolutions, including cleaning the build gradle and attempting to access various Health Connect permissions.
My current thought is that it has something to with the Health Connect intents since the dialog for Health Connect does not open in the simulator when awaiting requestPermission
.
Environment:
- Health Connect Version: 2024.31.21.00.release (beta)
- React Native Version: 0.73.6
- New architecture enabled: No
Thanks in advance for the help.
Same error here! Is it just happening in Android 14 to you too?
Edit: I don't know why react-native-health-connect 's docs don't tell us to include the following code in AndroidManifest.xml
. I added that and it worked.
https://developer.android.com/health-and-fitness/guides/health-connect/develop/get-started#show-privacy-policy
Ace solution @oscarparedez 👍
Revised my AndroidManifest.xml
as follows:
<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|screenSize|smallestScreenSize|uiMode"
android:launchMode="singleTask"
android:windowSoftInputMode="adjustResize"
android:exported="true">
...
<!-- For supported versions through Android 13, create an activity to show the rationale
of Health Connect permissions once users click the privacy policy link. -->
<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=".MainActivity"
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>
...
Confirmed operational on both Android 13 and Android 14.
The exact steps are already in the documentation:
https://matinzd.github.io/react-native-health-connect/docs/permissions/
Hope that helps!
Same error here! Is it just happening in Android 14 to you too?
Edit: I don't know why react-native-health-connect 's docs don't tell us to include the following code in
AndroidManifest.xml
. I added that and it worked. https://developer.android.com/health-and-fitness/guides/health-connect/develop/get-started#show-privacy-policy
The exact steps are already in the documentation:
https://matinzd.github.io/react-native-health-connect/docs/permissions/
Hope that helps!
Thanks @matinzd!