Android检索联系人姓名始终返回false

时间:2015-03-25 08:18:05

标签: android contact

我正在尝试检查给定名称是否与手机联系,但它总是返回false,我无法弄清楚我做了什么错误

public boolean ContactNotFound(String no, String name) {
    if (no != null) {
        Uri lookupUri = Uri.withAppendedPath(
                PhoneLookup.CONTENT_FILTER_URI, Uri.encode(name));
        String[] mPhoneNumberProjection = { PhoneLookup._ID,
                PhoneLookup.NUMBER, PhoneLookup.DISPLAY_NAME };
        Cursor cur = con.getContentResolver().query(lookupUri,
                mPhoneNumberProjection, null, null, null);

        LogUtil.d("Count -->" + cur.getCount());

        if (cur.getCount() > 0) {
            try {
                if (cur.moveToFirst()) {
                    return true;
                }
            } finally {
                if (cur != null)
                    cur.close();
            }
            return false;
        } else {
            return false;
        }

    } else {
        return false;
    }
}

请帮我弄清楚问题

1 个答案:

答案 0 :(得分:0)

我建议您暂时将所有联系人姓名保存在arraylist中,然后使用arrayList.contains(name)方法检查姓名