npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-native-select-contact-android

v0.8.1

Published

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

Downloads

12

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

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

Usage Example

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": "[email protected]"} ]
    }
    **/
  }

})

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