diff --git a/README.md b/README.md
index 01fceaa..04aa3ea 100644
--- a/README.md
+++ b/README.md
@@ -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
@@ -36,7 +41,8 @@ simpleContacts.getProfile().then((profile) => {
Function | Description
--- | ---
-**getContacts**() | Returns an array of contacts
+**getContacts**() | Returns an array of all contacts
+**getContactsByFilter**(*string*) | Returns an array of contacts by filter (eg: by email address)
**getProfile**() | Return the user's profile.
**findContactByNumber**(*number*) | Return the contact that matches the provided number.
diff --git a/android/src/main/java/ca/bigdata/voice/contacts/BDVSimpleContactsModule.java b/android/src/main/java/ca/bigdata/voice/contacts/BDVSimpleContactsModule.java
index 5bc77c9..6c99a30 100644
--- a/android/src/main/java/ca/bigdata/voice/contacts/BDVSimpleContactsModule.java
+++ b/android/src/main/java/ca/bigdata/voice/contacts/BDVSimpleContactsModule.java
@@ -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
@@ -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(