您好,登录后才能下订单哦!
Android中怎么查询联系人信息,很多新手对此不是很清楚,为了帮助大家解决这个难题,下面小编将为大家详细讲解,有这方面需求的人可以来学习下,希望你能有所收获。
Android查询联系人信息的功能主要是实现查询联系人的姓名,电话,邮件地址,
String columns[] = new String[] { People._ID, People.NAME,
People.NUMBER, People.PRIMARY_EMAIL_ID,People.PRIMARY_ORGANIZATION_ID, People.
PRIMARY_PHONE_ID, People.DISPLAY_NAME,People.IM_ACCOUNT, People.IM_HANDLE, People.PHONETIC_NAME, People.TYPE };
Uri mContacts = People.CONTENT_URI;
Cursor cur = managedQuery(mContacts, columns, // 要返回的数据字段
null, // WHERE子句
null, // WHERE 子句的参数
People.NAME // Order-by子句
);
if (cur.moveToFirst()) {
Cursor newcur = null;
do {
// 获取字段的值
String name = cur.getString(cur.getColumnIndex(People.NAME));
String phoneNo = cur.getString(cur.getColumnIndex(People.NUMBER));
String peopleId = cur.getString(cur.getColumnIndex(People._ID));
String[] PROJECTION = new String[] { Contacts.ContactMethods._ID,
Contacts.ContactMethods.KIND, Contacts.ContactMethods.DATA };newcur = managedQuery(Contacts.ContactMethods.CONTENT_URI,
PROJECTION, Contacts.ContactMethods.PERSON_ID + "=\'"+ cur.getLong(cur.getColumnIndex(People._ID)) + "\'", null, null);
startManagingCursor(newcur);
String email = "";
if (newcur.moveToFirst()) {
email = newcur.getString(newcur.getColumnIndex
(Contacts.ContactMethods.DATA));}
log.info("name = " + name + "
phoneNo = " + phoneNo + "email = " + email);if (email != null && !"".equals(email) &&
email.trim().length() != 0) {//此处可以取到联系人邮件
}
} while (cur.moveToNext());
if (newcur != null) {
newcur.close();//用完得关闭吧
}
}
if (cur != null)
cur.close(); //用完得关闭吧
看完上述内容是否对您有帮助呢?如果还想对相关知识有进一步的了解或阅读更多相关文章,请关注亿速云行业资讯频道,感谢您对亿速云的支持。
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。