Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ simpleContacts.getContacts().then((contacts) => {
// Do something with the contacts
});

// Get all contacts for filter string (eg: email address)
simpleContacts.getContactsByFilter("username@domain.example").then((contacts) => {
// Do something with the contact
});

// Get a specific contact based on a phone number
simpleContacts.findContactByNumber(number).then((contact) => {
// Do something with the contact
Expand All @@ -36,7 +41,8 @@ simpleContacts.getProfile().then((profile) => {

Function | Description
--- | ---
<nobr>**getContacts**()</nobr> | Returns an array of contacts
<nobr>**getContacts**()</nobr> | Returns an array of all contacts
<nobr>**getContactsByFilter**(*string*)</nobr> | Returns an array of contacts by filter (eg: by email address)
<nobr>**getProfile**()</nobr> | Return the user's profile.
<nobr>**findContactByNumber**(*number*)</nobr> | Return the contact that matches the provided number.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,19 @@ public String getName() {
@ReactMethod
public void getContacts(final Promise promise) {
Log.d(TAG, "getContacts");
Uri uri = ContactsContract.Contacts.CONTENT_URI;
this.getContactList(uri, promise);
}

@ReactMethod
public void getContactsByFilter(final String filter, final Promise promise) {
Log.d(TAG, "getContactsByFilter");
Uri uri = Uri.withAppendedPath(ContactsContract.Contacts.CONTENT_FILTER_URI, Uri.encode(filter));
this.getContactList(uri, promise);
}

private void getContactList(final Uri uri, final Promise promise) {
Log.d(TAG, "getContacts");

Thread thread = new Thread() {
@Override
Expand All @@ -50,14 +63,13 @@ public void run() {
JSONArray jsonA = new JSONArray();

Cursor cursor = cr.query(
ContactsContract.Contacts.CONTENT_URI,
uri,
new String[]{
ContactsContract.Contacts.DISPLAY_NAME,
ContactsContract.Contacts.PHOTO_THUMBNAIL_URI,
ContactsContract.Contacts._ID
},
null, null, null
);
null, null, null);
try {
while (cursor.moveToNext()) {
String contactID = cursor.getString(
Expand Down