Its crash on android when i use any method of this.
It works perfect on ios.
I tried to request permissions beforehand but nothing changed.
I tried to add READ_CONTACTS, WRITE_CONTACTS, READ_PROFILE, WRITE_PROFILE but nothing changed.
I tried manuel linking but nothing changed.
RN: 0.61.4
Android: R
react-native-contacts: 5.1.0
I just tried to use the module and it crashed on my android phone. It never prompted the READ_CONTACTS permission either. So I tried the following code to debug:
const granted = await PermissionsAndroid.request(
PermissionsAndroid.PERMISSIONS.READ_CONTACTS,
{
title: 'MyApp',
message: 'MyApp needs your permission to read contacts',
},
);
Alert.alert(granted.toString());
What it returned is the string "never_ask_again" (the other possible values I believe are "denied" and "granted"). It appears that I have "Don't ask again" option checked on the phone for contacts request. I have to add code to handle this case and display appropriate message and not call the React-Native-Contacts, or else it crashes. My Emulator also have the same issue, and the problem is that I am not able to find a way to reset "never_ask_again" so I can't really test the contacts now.
As @mochi08 mentioned the issue might be from permissions in newer versions of Android. Here is the issue and how I solved it:
Based on documentation, in AndroidManifest.xml you should add this line
<uses-permission android:name="android.permission.WRITE_CONTACTS" />
but then the js code for getting permission is asking for PermissionsAndroid.PERMISSIONS.READ_CONTACTS. So app would not have the permission which would make it never_ask_again. Since the library also does not handle this grant type, app crashes. Now how did I solve it? Under AndroidManifest.xml I changed the permission to <uses-permission android:name="android.permission.READ_CONTACTS" />
I think if you want write contact you can just have write contact in both AndroidManifest and js. It should work as long as they are consistent. Also make sure in your js permission request, handle the 'never_ask_again' case, since it can crash your app.
Feel free to submit a PR making the behavior more correct.
This issue is stale, please provide more information about the status
I just tried to use the module and it crashed on my android phone. It never prompted the READ_CONTACTS permission either. So I tried the following code to debug:
const granted = await PermissionsAndroid.request( PermissionsAndroid.PERMISSIONS.READ_CONTACTS, { title: 'MyApp', message: 'MyApp needs your permission to read contacts', }, ); Alert.alert(granted.toString());What it returned is the string "never_ask_again" (the other possible values I believe are "denied" and "granted"). It appears that I have "Don't ask again" option checked on the phone for contacts request. I have to add code to handle this case and display appropriate message and not call the React-Native-Contacts, or else it crashes. My Emulator also have the same issue, and the problem is that I am not able to find a way to reset "never_ask_again" so I can't really test the contacts now.
I also having the same problem just uninstall your app and install it again and also add the READ_CONTACTS permission in your Androidmanifest.xml file .
Most helpful comment
I also having the same problem just uninstall your app and install it again and also add the READ_CONTACTS permission in your Androidmanifest.xml file .