react-native-select-contact icon indicating copy to clipboard operation
react-native-select-contact copied to clipboard

Android Permissions error

Open SCasarotto opened this issue 6 years ago • 5 comments

I am receiving an android permission error even though I add this <uses-permission android:name="android.permission.READ_CONTACTS" /> to my AndroidManifest. any guesses? Works just fine on iOS. Even tried the react-native link but that didn't seem to resolve it.

SCasarotto avatar Jan 14 '20 02:01 SCasarotto

You need to request the READ_CONTACTS permission using PermissionsAndroid if your targetSdkVersion > 22.

ropmansk avatar Feb 27 '20 09:02 ropmansk

hi, import permision android import {PermissionsAndroid} from 'react-native';

and use this two method

getPhoneNumber = async () => {
    return selectContactPhone().then(selection => {
      if (!selection) {
        return null;
      }

      let {contact, selectedPhone} = selection;
      console.log(
        `Selected ${selectedPhone.type} phone number ${selectedPhone.number} from ${contact.name}`,
      );
      return selectedPhone.number;
    });
  }

requestContactPermission = async () => {
    try {
      const granted = await PermissionsAndroid.request(
        PermissionsAndroid.PERMISSIONS.READ_CONTACTS,
        {
          title: 'Allow Access Contact?',
          message:
            'allow this app to read contact information',
          buttonNegative: 'Cancel',
          buttonPositive: 'OK',
        },
      );
      if (granted === PermissionsAndroid.RESULTS.GRANTED) {
        console.log('granted');
        this.getPhoneNumber();
      } else {
        console.log('denied');
      }
    } catch (err) {
      console.warn(err);
    }
  }

and call from jsx this.requestContactPermission();

have a nice day :D

GusNando avatar Mar 16 '20 13:03 GusNando

thank you @GusNando for the explanation. in my Xiaomi Redmi 6, after popup permission show and click the Allow button, the code after await request permission is not excuted, so i can not get the granted value. How to fix it?

moxspoy avatar Mar 19 '20 09:03 moxspoy

did you added <uses-permission android:name="android.permission.READ_CONTACTS" /> in android manifest? and can you share some of your code?

GusNando avatar Mar 27 '20 14:03 GusNando

import {PermissionsAndroid} from 'react-native';

ameer0706 avatar Feb 10 '23 06:02 ameer0706