我是Android的新手,目前我可以从Google Contact中检索联系人列表和图像。但是,我的应用程序中的联系人列表没有像Google Gmail应用那样提供我公司中电子邮件的建议。
有可能我可以检索这些额外的电子邮件地址吗?
以下是检索联系人的代码
public ArrayList<String> getNameEmailDetails() {
ArrayList<String> emlRecs = new ArrayList<String>();
HashSet<String> emlRecsHS = new HashSet<String>();
ContentResolver cr = getContentResolver();
String[] PROJECTION = new String[] { ContactsContract.RawContacts._ID,
ContactsContract.Contacts.DISPLAY_NAME,
ContactsContract.Contacts.PHOTO_ID,
ContactsContract.CommonDataKinds.Email.DATA,
ContactsContract.CommonDataKinds.Photo.CONTACT_ID };
String order = "CASE WHEN "
+ ContactsContract.Contacts.DISPLAY_NAME
+ " NOT LIKE '%@%' THEN 1 ELSE 2 END, "
+ ContactsContract.Contacts.DISPLAY_NAME
+ ", "
+ ContactsContract.CommonDataKinds.Email.DATA
+ " COLLATE NOCASE";
String filter = ContactsContract.CommonDataKinds.Email.DATA + " NOT LIKE ''";
Cursor cur = cr.query(ContactsContract.CommonDataKinds.Email.CONTENT_URI, PROJECTION, filter, null, order);
if (cur.moveToFirst()) {
do {
// names comes in hand sometimes
String name = cur.getString(1);
String email = cur.getString(3);
String contact_id = cur.getString(4);
Bitmap profilePic = openPhoto(Long.parseLong(contact_id));
if (profilePic != null) {
profileList.add(new WordMatchAdapterWithIMG.profileWithIMG(email, profilePic));
}
} while (cur.moveToNext());
}
cur.close();
return emlRecs;
}
我建议您使用Google Contacts API。
Google Contacts API允许客户端应用程序查看和更新用户的联系人。联系人存储在用户的Google帐户中;大多数Google服务都可以访问联系人列表。
要检索单个联系人,请发送授权 GET
请求到联系人的自链接URL:
https://www.google.com/m8/feeds/contacts/{useremail}/full/fult/{contactID}
成功后,服务器响应 HTTP 200 OK
状态代码和请求的联系人条目。
公共静态接触式检索(ContactsService MyService){confictentry contact =myService.getEntry(new url(" https://www.google.com/m8/feeds/contacts/default/default/full/contactid"),confictentry.class);//与联系人做点什么。返回联系人;}
有用的材料
- 使用Google Contacts API和OAUTH2在Android中获取Google/gmail联系人
- php gmail触点XML与Domdocument和Curl