streem / react-native-select-contact

A cross-platform contact selection library for react-native
MIT License
114 stars 50 forks source link

Error: Cannot open the contact selector twice on Android #53

Open bellalzohir opened 2 years ago

bellalzohir commented 2 years ago

it works well before on android 7-9 but I face this error:Cannot open the contact selector twice on Android 11

mohamedmoawia commented 2 years ago

I am facing the same issue, are there any updates regarding this issue?

seanadkinson commented 2 years ago

Looking at this function, it doesn't seem like you would get into this situation, except if opening the contact selector were remaining open, without resolving the promise. When you get this error, is it typically on a second attempt to open the selector? If so, does the first attempt succeed or fail, or do nothing?

mohamedmoawia commented 2 years ago

it does nothing

mohamedmoawia commented 2 years ago

@seanadkinson as you said it is happens with the second attempt, but the first attempts doesn't open the contacts menu on android 11, it is working with 9 and 10 but not 11

seanadkinson commented 2 years ago

No info in the Android logs that would help narrow it down? Some have reported issues with permissions on Android, so you might need to request READ_CONTACTS before initiating the contact selector. See this thread.

And you already added <uses-permission android:name="android.permission.READ_CONTACTS" /> to the manifest, correct?

mohamedmoawia commented 2 years ago

I already added the permission to manifest, and also asking for using react-native-permissions

    let response =
      Platform.OS === 'ios'
        ? await request(PERMISSIONS.IOS.CONTACTS)
        : await request(PERMISSIONS.ANDROID.READ_CONTACTS);
    if (response === 'denied') {
      console.log('denied');
    }
    if (response == 'granted')
      return selectContactPhone().then(
        selection => {
          if (!selection) {
            return null;
          }
          let {contact, selectedPhone} = selection;
          let number = selectedPhone.number.replace(/ /g, ''); //trim spaces
          if (
            (number.startsWith('02') || number.startsWith('+2')) &&
            service.is_contact &&
            !(service.max_length == 10)
          )
            setRefrenceValue(number.slice(2));
          else setRefrenceValue(number);
          return selectedPhone.number;
        },
        err => {
          console.log('GET CONTACT NUMBER ERRRORRR: ', err);
        },
      );
  };
mohamedmoawia commented 2 years ago

I found the solution for this in another issue solution:

solution : Need to add below lines in AndroidManifest

......
</application>
    <queries>
        <intent>
            <action android:name="android.intent.action.VIEW" />
            <category android:name="android.intent.category.DEFAULT" />
            <data android:mimeType="vnd.android.cursor.dir/contact" />
        </intent>
    </queries>
</manifest>

Originally posted by @SomnathKadam in https://github.com/streem/react-native-select-contact/issues/42#issuecomment-851635569

seanadkinson commented 2 years ago

Ah, very good! Would you be interested in adding documentation, and updating our README with a PR?

mohamedmoawia commented 2 years ago

@seanadkinson I have no problem, but what do you mean by PR?

seanadkinson commented 2 years ago

PR = Pull Request. That is, branch this repo, make the change, and send it back to us in a Pull Request here on github. Thanks! Let me know if you'd like any additional guidance. Really appreciate you being willing to help keep the docs up to date.

shubhsd commented 2 years ago

I found the solution for this in another issue solution:

solution : Need to add below lines in AndroidManifest

......
</application>
    <queries>
        <intent>
            <action android:name="android.intent.action.VIEW" />
            <category android:name="android.intent.category.DEFAULT" />
            <data android:mimeType="vnd.android.cursor.dir/contact" />
        </intent>
    </queries>
</manifest>

Originally posted by @SomnathKadam in #42 (comment)

Works like charm

Tgirmay commented 2 years ago

I have the same issue on iOS but the first time I try opening it, I get this log which appears to be the issue in #28

 [TypeError: null is not an object (evaluating 'SelectContact.openContactSelection')]
imamrobani commented 2 years ago
<intent-filter>
     <action android:name="android.intent.action.PICK" />
     <category android:name="android.intent.category.DEFAULT" />
     <data android:mimeType="vnd.android.cursor.dir/contact" />
</intent-filter>

it works for me. Change action.VIEW to action.PICK

Oluwaturheeb commented 1 year ago

I found the solution for this in another issue solution:

solution : Need to add below lines in AndroidManifest

......
</application>
    <queries>
        <intent>
            <action android:name="android.intent.action.VIEW" />
            <category android:name="android.intent.category.DEFAULT" />
            <data android:mimeType="vnd.android.cursor.dir/contact" />
        </intent>
    </queries>
</manifest>

Originally posted by @SomnathKadam in #42 (comment)

This worked for me on Android 13, kindly add this to the README.

seanadkinson commented 1 year ago

@Oluwaturheeb , I think this is already in the README here: https://github.com/streem/react-native-select-contact/blob/master/README.md#android

Let me know if there is an update needed that I'm not seeing.