streem / react-native-select-contact

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

Issue in Android 11, Contact picker not open #42

Closed SomnathKadam closed 3 years ago

SomnathKadam commented 3 years ago

Hi Team,

facing issue in Android 11 Contact picker not open, with below code

import { selectContactPhone } from 'react-native-select-contact';


const 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) {
                getPhoneNumber();
            }
        } catch (err) {
            console.warn(err);
        }
    };

const getPhoneNumber = async () => {
        selectContactPhone()
            .then((selection) => {
                if (!selection) {
                    return null;
                }
                let { contact, selectedPhone } = selection;
                console.log(
                    `Selected ${selectedPhone.type} phone number ${selectedPhone.number} from ${contact.name}`
                );

            })
            .catch((err) => {
                console.log(err);
            });
    };

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>
SomnathKadam commented 3 years ago

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>
ahron1 commented 3 years ago

For any future visitors to this issue - The underlying reference is this -

https://developer.android.com/training/package-visibility

thanhluantl2304 commented 3 years ago

this should be added to Documentation

bijaykanshinew commented 2 years ago

i added this line

<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>

but it's still not working. it's closing the app without any error

imamrobani commented 2 years ago

i added this line

<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>

but it's still not working. it's closing the app without any error

yes, I still facing this issue on android 11, anyone can help?

flyjeray commented 1 year ago

Late answer but I've encountered the same problem:

If you don't really know, how AndroidManifest works (as example, I don't), make sure that you don't mix intent blocks

<intent>
      <action android:name="android.intent.action.VIEW" />
      <category android:name="android.intent.category.DEFAULT" />
      <data android:mimeType="vnd.android.cursor.dir/contact" />
      <category android:name="android.intent.category.BROWSABLE"/>
      <data android:scheme="https"/>
</intent>

^ This will NOT work ^

<intent>
    <category android:name="android.intent.category.BROWSABLE"/>
    <data android:scheme="https"/>
</intent>
<intent>
    <action android:name="android.intent.action.VIEW" />
    <category android:name="android.intent.category.DEFAULT" />
    <data android:mimeType="vnd.android.cursor.dir/contact" />
</intent>

^ This is correct ^

A bit dumb situation, but it's better to save other beginners from spending hours on this :)