您好,登录后才能下订单哦!
本文小编为大家详细介绍“Android中如何查询联系人信息”,内容详细,步骤清晰,细节处理妥当,希望这篇“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(); //用完得关闭吧
读到这里,这篇“Android中如何查询联系人信息”文章已经介绍完毕,想要掌握这篇文章的知识点还需要大家自己动手实践使用过才能领会,如果想了解更多相关内容的文章,欢迎关注亿速云行业资讯频道。
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。