How to request Android 2.x contacts with emails and / or phone numbers?

Let go over your Android 2.x Visible Contact ID / Names garden pointer (via ContactsContract ):

Cursor c = getContentResolver().query(
  Contacts.CONTENT_URI,
  new String[] { Contacts._ID, Contacts.DISPLAY_NAME },
  Contacts.IN_VISIBLE_GROUP + " = '1'",
  null,
  Contacts.DISPLAY_NAME + " COLLATE LOCALIZED ASC"
);

Is there any way to filter this to get contacts that have at least one email address and / or phone number?

I see that I can use Contacts.HAS_PHONE_NUMBER ... but I do not see HAS_EMAIL anywhere. (Say it won't look ugly.)

+3
source share
2 answers

Uri. , android.provider.ContactsContract.CommonDataKinds.Email , (, IN_VISIBLE_GROUP) .

, URI .

+4

, :

Cursor c = getContentResolver().query(ContactsContract.Contacts.CONTENT_URI, null, null, null, null);
String[] names = c.getColumnNames();
for (String string : names) {
    Log.d("ContactList", "RC column " + string);
}
c.close();

has_email. .

0

Source: https://habr.com/ru/post/1783748/


All Articles