android中读取通讯录学习笔记

1、读取通讯录时一次读取时,尽量少读取全部属性。特别是列表展示的时候。会让你的列表载入速度变得难以忍受,建议先载入少量属性。然后在详情的时候载入全部属性。

2、在读取一类属性的时候,建议用一个游标,且放在循环外面,能明显加高速度,用projection(表示须要查询的列,在以下代码中是CONTACTOR_ION)

演示样例代码例如以下:

private static final String[] CONTACTOR_ION = new String[]{
		ContactsContract.CommonDataKinds.Phone.CONTACT_ID,
		ContactsContract.Contacts.DISPLAY_NAME,
		ContactsContract.CommonDataKinds.Phone.NUMBER
	};

。。

Cursor phones = null;
		ContentResolver cr = getContentResolver();
		try {
			phones = cr
					.query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI
							, CONTACTOR_ION, null, null, "sort_key");
			
			if (phones != null) {
				final int contactIdIndex = phones.getColumnIndex(ContactsContract.CommonDataKinds.Phone.CONTACT_ID);
				final int displayNameIndex = phones.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME);
				final int phoneIndex = phones.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER);
				String phoneString, displayNameString, contactIdString;
				while (phones.moveToNext()) {
					LinkManForm linkManForm = new LinkManForm();
					phoneString = phones.getString(phoneIndex);
					displayNameString = phones.getString(displayNameIndex);
					contactIdString = phones.getString(contactIdIndex);
				}
			}
} catch (Exception e) {
			Log.e(TAG, e.getMessage());
		} finally {
			if (phones != null)
				phones.close();
		}

3、查询联系人的部门属性是ORGANIZATION.TITLE,而不是ORGANZITION.DEPARTMENT,这个是个坑。



转载于:https://www.cnblogs.com/zhchoutai/p/6911555.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值