从电子邮件地址查询联系人时获取两行

时间:2014-12-08 03:58:52

标签: android android-contentprovider android-cursor

我收到了一个电子邮件地址,我希望得到该用户的contact_id。

String whereClause = null;
if(android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.HONEYCOMB)
{
    //Field requires API level 11
    whereClause = ContactsContract.CommonDataKinds.Email.ADDRESS + " = '" + email + "'";
} else
{
    whereClause = "data1" + " = '" + email + "'";
}

Cursor user = context.getContentResolver().query(
        ContactsContract.CommonDataKinds.Email.CONTENT_URI,
        new String[] {ContactsContract.CommonDataKinds.Email.CONTACT_ID},
        whereClause,
        null,
        null);

DataUtils.log("In getContactFromEmail, cursor is " + DatabaseUtils.dumpCursorToString(user));

日志打印显示光标有2个结果:

12-07 21:56:51.410: V/talk(7491): In getContactFromEmail, cursor is >>>>> Dumping cursor android.content.ContentResolver$CursorWrapperInner@52a379a4
12-07 21:56:51.410: V/talk(7491): 0 {
12-07 21:56:51.410: V/talk(7491):    contact_id=840
12-07 21:56:51.410: V/talk(7491): }
12-07 21:56:51.410: V/talk(7491): 1 {
12-07 21:56:51.410: V/talk(7491):    contact_id=902
12-07 21:56:51.410: V/talk(7491): }

我期待的是contact_id=902而不是第一个。我已经检查过,系统中没有其他联系人收到此电子邮件。

任何可能导致此问题的想法?

谢谢!

0 个答案:

没有答案