react-native-contacts icon indicating copy to clipboard operation
react-native-contacts copied to clipboard

Does not request permission on android when calling requestPermission

Open jebora opened this issue 9 years ago • 3 comments

When using requestPermission ReactMethod on android ContactsManager react module, it only checks if permission for READ_CONTACTS is granted. It needs to prompt user for permission for API 23+

@ReactMethod
public void requestPermission(Callback callback) {
    callback.invoke(null, isPermissionGranted());
}

Line Reference

jebora avatar May 25 '17 20:05 jebora

You need to specifically handle the Android case with PermissionsAndroid.request like so:

const granted = await PermissionsAndroid.request(
        PermissionsAndroid.PERMISSIONS.READ_CONTACTS,
        {
          title: 'Permission to Read Contacts',
          message: 'MyContacts needs permission to read contacts'
        },
        PermissionsAndroid.PERMISSIONS.WRITE_CONTACTS,
        {
          title: 'Permission to Write Contacts',
          message: 'MyContacts needs permission to write contacts'
        },
        PermissionsAndroid.PERMISSIONS.READ_PROFILE,
        {
          title: 'Permission to Read Profile',
          message: 'MyContacts needs permission to read profile'
        }
      );

This worked for me.

nfplay avatar Jun 06 '17 18:06 nfplay

@nfplay did you remove the uses-permission tags from your AndroidManifest.xml to get this to work?

  <!-- FOR CONTACTS LIBRARY -->
  <uses-permission android:name="android.permission.READ_PROFILE" />
  <uses-permission android:name="android.permission.READ_CONTACTS" />

I removed them but in my JS code when I use PermissionsAndroid.request to get READ_CONTACTS and READ_PROFILE permissions I keep getting returned never_ask_again.

ArcadeRenegade avatar Sep 25 '17 00:09 ArcadeRenegade

Also READ_PROFILE does not exist in PermissionsAndroid.PERMISSIONS unfortunately as of RN 0.48

ArcadeRenegade avatar Sep 25 '17 00:09 ArcadeRenegade