安卓联系人 检查联系人是否有电子邮件 ID



我得到了使用
HAS_PHONE_NUMBER

ContentResolver ContntRslverVar = getContentResolver();
Cursor ContctCorsorVar = ContntRslverVar.query(ContactsContract.Contacts.CONTENT_URI, null, null, null, null);
while (ContctCorsorVar.moveToNext())
{
    if (Integer.parseInt(ContctCorsorVar.getString(ContctCorsorVar.getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER))) > 0)
    {
    }
}

类似是检查电子邮件的一种方式?
HAS_EMAIL

if (Integer.parseInt(ContctCorsorVar.getString(ContctCorsorVar.getColumnIndex(ContactsContract.Contacts.HAS_EMAIL))) > 0)
{
}

作为一种解决方法,您可以运行单个查询来获取所有包含电子邮件的联系人 ID,将这些 ID 存储在一个集中,并将其用作"HAS_EMAIL"引用:

Set<Long> hasEmail = new HashSet<>();
// The Email class should be imported from CommonDataKinds.Email
Cursor cursor = getContentResolver().query(Email.CONTENT_URI, new String[] { Email.CONTACT_ID }, null, null, null); 
while (cursor != null && cursor.moveToNext()) {
    hasEmail.add(cursor.getLong(0));
}
if (cursor != null) {
    cursor.close();
}
// now you can check if a contact has an email via:
if (hasEmail.contains(someContactId)) {
    // do something
}
// or iterate over all contact-ids that has an email
Iterator<Long> it = hasEmail.iterator();
while(it.hasNext()) {
    Long contactId = it.next();
    // do something
}

相关内容

  • 没有找到相关文章

最新更新