我正在尝试获取代码来搜索交换和Gmail联系人。 但我最终只使用了搜索本地地址簿的代码。
public void contactSearch(String name)
{
name=name.toLowerCase();
ContentResolver resolver = getContentResolver();
Cursor c = resolver.query(
ContactsContract.Data.CONTENT_URI,
null,
ContactsContract.Data.HAS_PHONE_NUMBER + "!=0 AND (" + ContactsContract.Data.MIMETYPE + "=? OR " + ContactsContract.Data.MIMETYPE + "=?)",
new String[]{ContactsContract.CommonDataKinds.Email.CONTENT_ITEM_TYPE},
ContactsContract.Data.CONTACT_ID);
while (c.moveToNext()) {
if(c.getString(c.getColumnIndex(ContactsContract.Data.DISPLAY_NAME)).toLowerCase().contains(name)||c.getString(c.getColumnIndex(ContactsContract.Data.DATA1)).contains(name)) {
Log.w("All contacts Data", getdetails(c.getString(c.getColumnIndex(ContactsContract.Data.DISPLAY_NAME)), c.getString(c.getColumnIndex(ContactsContract.Data.DATA1))).toString());
}
}
c.close();
}
public HashMap<String,String> getdetails(String name,String email)
{
HashMap<String, String> contactDetail = new HashMap<String, String>();
contactDetail.put("name", name);
contactDetail.put("email", email);
return contactDetail;
}
如果用户不在本地联系人目录中,有人可以告诉我如何搜索Exchange和GMail联系人吗?