开发者

How to query Android 2.x Contacts with Emails and/or Phone Numbers?

Let's brute force your garden-variety Android 2.x Visible Contact ID/Names cursor (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 a way to filter this to get contacts that only have at least one email and/or phone number?

I开发者_如何学Python see that I can use Contacts.HAS_PHONE_NUMBER ... but I don't see HAS_EMAIL anywhere. (Tell me this isn't going to get ugly.)


Query on the appropriate content provider Uri. For example, android.provider.ContactsContract.CommonDataKinds.Email lets you obtain email addresses, and your other columns (e.g., IN_VISIBLE_GROUP) are implicitly joined in.

Here is a sample project that demonstrates using these other content provider Uri values.


I just enumerated the columns on a cursor fetched on Contacts like that:

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();

The result contains has_email. It may be specific to the galaxy tab, though.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜