@@ -107,6 +107,9 @@ public void onMethodCall(MethodCall call, Result result) {
107
107
} case "getContactsForPhone" : {
108
108
this .getContactsForPhone (call .method , (String )call .argument ("phone" ), (boolean )call .argument ("withThumbnails" ), (boolean )call .argument ("photoHighResolution" ), (boolean )call .argument ("orderByGivenName" ), (boolean )call .argument ("androidLocalizedLabels" ), result );
109
109
break ;
110
+ } case "getContactsForEmail" : {
111
+ this .getContactsForEmail (call .method , (String )call .argument ("email" ), (boolean )call .argument ("withThumbnails" ), (boolean )call .argument ("photoHighResolution" ), (boolean )call .argument ("orderByGivenName" ), (boolean )call .argument ("androidLocalizedLabels" ), result );
112
+ break ;
110
113
} case "getAvatar" : {
111
114
final Contact contact = Contact .fromMap ((HashMap )call .argument ("contact" ));
112
115
this .getAvatar (contact , (boolean )call .argument ("photoHighResolution" ), result );
@@ -212,6 +215,10 @@ private void getContactsForPhone(String callMethod, String phone, boolean withTh
212
215
new GetContactsTask (callMethod , result , withThumbnails , photoHighResolution , orderByGivenName , localizedLabels ).executeOnExecutor (executor , phone , true );
213
216
}
214
217
218
+ private void getContactsForEmail (String callMethod , String email , boolean withThumbnails , boolean photoHighResolution , boolean orderByGivenName , boolean localizedLabels , Result result ) {
219
+ new GetContactsTask (callMethod , result , withThumbnails , photoHighResolution , orderByGivenName , localizedLabels ).executeOnExecutor (executor , email , true );
220
+ }
221
+
215
222
@ Override
216
223
public void onAttachedToActivity (ActivityPluginBinding binding ) {
217
224
if (delegate instanceof ContactServiceDelegate ) {
@@ -443,6 +450,7 @@ protected ArrayList<HashMap> doInBackground(Object... params) {
443
450
case "openDeviceContactPicker" : contacts = getContactsFrom (getCursor (null , (String ) params [0 ]), localizedLabels ); break ;
444
451
case "getContacts" : contacts = getContactsFrom (getCursor ((String ) params [0 ], null ), localizedLabels ); break ;
445
452
case "getContactsForPhone" : contacts = getContactsFrom (getCursorForPhone (((String ) params [0 ])), localizedLabels ); break ;
453
+ case "getContactsForEmail" : contacts = getContactsFrom (getCursorForEmail (((String ) params [0 ])), localizedLabels ); break ;
446
454
default : return null ;
447
455
}
448
456
@@ -537,6 +545,14 @@ private Cursor getCursorForPhone(String phone) {
537
545
return null ;
538
546
}
539
547
548
+ private Cursor getCursorForEmail (String email ) {
549
+ if (email .isEmpty ())
550
+ return null ;
551
+ ArrayList <String > selectionArgs = new ArrayList <>(Arrays .asList ("%" + email + "%" ));
552
+ String selection = Email .ADDRESS + " LIKE ?" ;
553
+ return contentResolver .query (ContactsContract .Data .CONTENT_URI , PROJECTION , selection , selectionArgs .toArray (new String [selectionArgs .size ()]), null );
554
+ }
555
+
540
556
/**
541
557
* Builds the list of contacts from the cursor
542
558
* @param cursor
0 commit comments