react-native-android-contactpicker
This is a react native module that wraps Android-ContactPicker to facilitate selecting multiple contacts in one intent. This is for android version 5 (or higher) only.
After upgrading, make sure to clean before compiling:
cd android && ./gradlew clean && cd ..
Installation
npm install --save react-native-android-contactpicker
Usage Example
var ContactPicker = ContactPicker /**Sample contact list:[ { id: "100", name: { display:"John Doe", first: "John", last: "Doe" }, phoneNumbers: [ {"number": "+1-555-555-5555"} ], emailAddresses: [ {"email": "john.doe@email.com"} ] }]**/
Options
Property | Description |
---|---|
theme (int) | This option sets the theme for Android-ContactPicker multi-select view only Default: ContactPicker.Themes.LIGHT |
limit (int) | This parameter will limit the amount of contacts that can be selected per intent. When set to zero, then no limiting will be enforced Default: 0 |
limitReachedMessage (String) | This parameter sets the text displayed as a toast when the set limit is reached Default: You can't pick more than {limit} contacts! |
showCheckAll (Boolean) | This parameter decides whether to show/hide the check_all button in the menu. When limit > 0, this will be forced to false . Default: true |
onlyWithPhone (Boolean) | This parameter sets the boolean that filters contacts that have no phone numbers Default: false |
Constants
ContactPicker.Themes = {
DARK,
LIGHT
}
ContactPicker.Errors = {
UNSUPPORTED,
USER_CANCEL
}
Getting Started - Android
- In
android/settings.gradle
...include ':react-native-android-contactpicker'project(':react-native-android-contactpicker').projectDir = new File(settingsDir, '../node_modules/react-native-android-contactpicker/android')
- In
android/app/build.gradle
...dependencies { ... compile project(':react-native-android-contactpicker')}
- register module (in android/app/src/main/java/{your-app-namespace}/MainApplication.java)
// <------ add import
- Add Contacts permission and Activity (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.
Possible Promise Rejection Reasons
The following will cause a rejection that invokes the catch method of the promise 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
-
User hits the back button and never picks a contact.
Known issues
- If you select too many contacts, there will be an exception that crashes the app. details. The Best way to avoid this is to limit the amount of contacts a user can select per intent.
Acknowledgements and Special Notes
- @rhaker's react-native-select-contact-android Issue #5 started the initiative.
- @1gravity for the awesome library and being open to accepting new features in the Android-ContactPicker library.