From 864dc8862328455100da85499d1db2e203095fa4 Mon Sep 17 00:00:00 2001 From: Harry Moreno Date: Fri, 18 Jan 2019 15:07:04 -0500 Subject: [PATCH] Document android permissions request closes https://github.com/rt2zz/react-native-contacts/issues/218 --- README.md | 34 ++++++++++++++++++++++++++++------ 1 file changed, 28 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index e24a7726..666b1f26 100644 --- a/README.md +++ b/README.md @@ -10,10 +10,10 @@ Ask questions on [stackoverflow](https://stackoverflow.com/questions/tagged/reac import Contacts from 'react-native-contacts'; Contacts.getAll((err, contacts) => { - if (err) throw err; - + if (err) { + throw err; + } // contacts returned - console.log(contacts) }) ``` @@ -23,10 +23,32 @@ Contacts.getAll((err, contacts) => { import Contacts from 'react-native-contacts'; Contacts.getContactsMatchingString("filter", (err, contacts) => { - if (err) throw err; - + if (err) { + throw err; + } // contacts matching "filter" - console.log(contacts) +}) +``` +### Android permissions +On android you must request permissions beforehand +```es +import { PermissionsAndroid } from 'react-native'; +import Contacts from 'react-native-contacts'; + +PermissionsAndroid.request( + PermissionsAndroid.PERMISSIONS.READ_CONTACTS, + { + 'title': 'Contacts', + 'message': 'This app would like to view your contacts.' + } +).then(() => { + Contacts.getAll((err, contacts) => { + if (err === 'denied'){ + // error + } else { + // contacts returned in Array + } + }) }) ``` ## Installation