# react-native-select-contact-android

> A react-native module for tapping on a contact and returning a name, email, and phone.

Latest version **0.8.1** (published 2017-08-27) · MIT license · 0 weekly downloads

## Install

```sh
npm install react-native-select-contact-android
pnpm add react-native-select-contact-android
yarn add react-native-select-contact-android
bun add react-native-select-contact-android
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.8.1 |
| Published | 2017-08-27 |
| First published | 2015-11-30 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 13 |
| Author | rhaker |
| Maintainers | rhaker |
| Keywords | react-component, react-native, android, contact, addressbook, email |

## Links

- npm: https://www.npmjs.com/package/react-native-select-contact-android
- Repository: github.com:rhaker/react-native-select-contact-android
- Homepage: https://github.com/rhaker/react-native-select-contact-android
- Issues: https://github.com/rhaker/react-native-select-contact-android/issues
- npm.io page: https://npm.io/package/react-native-select-contact-android

## Alternatives

- [@expo/fingerprint](https://npm.io/package/@expo/fingerprint.md) — 6.2M weekly downloads
- [@azure/monitor-opentelemetry-exporter](https://npm.io/package/@azure/monitor-opentelemetry-exporter.md) — 850.0K weekly downloads
- [@azure/monitor-opentelemetry](https://npm.io/package/@azure/monitor-opentelemetry.md) — 624.0K weekly downloads
- [@posthog/ai](https://npm.io/package/@posthog/ai.md) — 423.3K weekly downloads
- [fakefilter](https://npm.io/package/fakefilter.md) — 63.9K weekly downloads

## Recent versions

- 0.8.1 (latest) — 2017-08-27
- 0.7.1 — 2016-10-19
- 0.6.1 — 2016-09-29
- 0.5.1 — 2016-09-26
- 0.4.1 — 2016-01-22
- 0.3.1 — 2015-12-23
- 0.2.1 — 2015-12-03
- 0.1.1 — 2015-11-30
- 0.1.0 — 2015-11-30

## README

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

```js
npm install react-native-select-contact-android --save
```

## Usage Example

```js
var SelectContacts = require('react-native-select-contact-android')

SelectContacts.pickContact({timeout: 45000}, (err, contact) => {

  if (err){
    if(typeof err === 'object'){
      if (err.message == "user canceled") {
        console.log("user hit back button in contact picker");
      } else if (err.message == "timed out") {
        console.log("timed out");
      } else if (err.message == "android version not supported") {
        console.log("invalid android version");
      }
    }
    // log out err object
    console.log(err)
  } else {  
    console.log(contact.name);
    console.log(contact.phoneNumbers);
    console.log(contact.emailAddresses);
    console.log(contact)
    /**
    Sample contact:
    {
      id: "100",
      name: "John Doe",
      phoneNumbers: [ {"number": "+1-555-555-5555"} ],
      emailAddresses: [ {"email": "john.doe@email.com"} ]
    }
    **/
  }

})
```

### Options

| Property  | Description  |
|---|---|
|  **timeout** (number)  |  Value in milliseconds (ms) that states how long to wait for the user to select a contact <br/> Default: `45000` |  


## Getting Started - Android
* In `android/settings.gradle`
```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`
```gradle
...
dependencies {
    ...
    compile project(':react-native-select-contact-android')
}
```

* register module (in android/app/src/main/java/[your-app-namespace]/MainApplication.java)
```java
import com.rhaker.reactnativeselectcontacts.ReactNativeSelectContacts; // <------ add import

public class MainApplication extends Application implements ReactApplication {
  private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) {

    ...

    @Override
    protected List<ReactPackage> getPackages() {
      return Arrays.<ReactPackage>asList(
          new MainReactPackage(),
          new ReactNativeSelectContacts()
      );
    }
  };

  ...
}
```

* add Contacts permission (in android/app/src/main/AndroidManifest.xml)
```xml
...
  <uses-permission android:name="android.permission.READ_CONTACTS" />
...
```
## 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):

1) Android Version below 5.0 is used.

2) User denies access to the addressbook

3) The user takes longer than 45 seconds to pick a contact.

4) User hits the back button and never picks a contact.

## Acknowledgements and Special Notes

This module has been updated by [@lwhiteley](https://github.com/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.

---
_Source: https://npm.io/package/react-native-select-contact-android · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
