react-native-select-contact-android
This is a react native module that launches the addressbook and when the user taps on a contact various fields (name, phone, and email) are returned. This is for android version 5 (or higher) only.
For ios, you can use one of the many select-contact-* modules I have previously built.
If you want to be able to select multiple contacts at once for android, please use https://github.com/lwhiteley/react-native-android-contactpicker by @lwhiteley
Installation
npm install react-native-select-contact-android --save
Usage Example
var SelectContacts = SelectContacts
Options
Property | Description |
---|---|
timeout (number) | Value in milliseconds (ms) that states how long to wait for the user to select a contact Default: 45000 |
Getting Started - Android
- In
android/settings.gradle
...include ':react-native-select-contact-android'project(':react-native-select-contact-android').projectDir = new File(settingsDir, '../node_modules/react-native-select-contact-android/android')
- In
android/app/build.gradle
...dependencies { ... compile project(':react-native-select-contact-android')}
- register module (in android/app/src/main/java/[your-app-namespace]/MainApplication.java)
// <------ add import
- add Contacts permission (in android/app/src/main/AndroidManifest.xml)
... ...
Additional Notes
The properties phoneNumbers and emailAddresses will be returned as empty arrays if no phone numbers or emails are found.
Error Callback
The following will cause a callback that indicates an error (use the console.log to see the specific message):
-
Android Version below 5.0 is used.
-
User denies access to the addressbook
-
The user takes longer than 45 seconds to pick a contact.
-
User hits the back button and never picks a contact.
Acknowledgements and Special Notes
This module has been updated by @lwhiteley to handle RN version 0.29+. Special thanks for all the hard work!
The approach prior to @lwhiteley's version relied heavily on @satya164 comments at https://github.com/facebook/react-native/issues/3334. If you are using a module that also uses his approach, you might have to make some adjustments. Special thanks also to @rt2zz and his react-native-contacts repo. Finally, Brent Vatne is always amazingly helpful with everything and deserves to be thanked.