Android中获取手机联系人的优化
2015-05-15 18:14
309 查看
1.优化方案
Map<String, String> temp = new HashMap<String, String>(); String[] phoneNumberProjection = new String[]{ ContactsContract.CommonDataKinds.Phone.CONTACT_ID, ContactsContract.CommonDataKinds.Phone.NUMBER, ContactsContract.Contacts.DISPLAY_NAME}; Cursor c = context.getContentResolver().query( ContactsContract.CommonDataKinds.Phone.CONTENT_URI, phoneNumberProjection, null, null, null); if (c != null) { long startTime = System.currentTimeMillis(); if (c.moveToFirst()) { do { String contactId = c.getString(0); String name = c.getString(2); String number = c.getString(1); System.out.print(contactId + ":" + name + "\n"); temp.put(name, number); } while (c.moveToNext()); } c.close(); long endTime = System.currentTimeMillis(); long time = endTime - startTime; System.out.println((float) (time / 1000) + "秒"); } return temp;
2.说明
获取联系人姓名和电话号码只要查询一遍数据库,参考代码 http://www.icodelogic.com/?p=453 经测试,100条联系人之前查询用时2s,优化后用时0s.相关文章推荐
- android 获取手机联系人
- android利用ContentResolver访问者获取手机联系人信息
- Android基础教程(四)之------获取手机联系人信息
- Android获取手机联系人listView展示
- 如何获取android手机联系人并按字母展示(二)
- Android 获取手机联系人之方式二
- Android进阶篇-获取手机通讯录联系人头像
- Android 获取手机联系人信息
- Android简单获取手机联系人姓名电话号码
- Android中获取手机中的联系人信息
- Android项目实战-获取手机本地联系人,并带字母导航栏
- Android程序:获取手机通讯录并用优化后的listview显示
- 如何获取android手机联系人并按字母展示(三)
- Android 获取手机联系人
- Android开发之contentprovider获取手机所有联系人(姓名、号码、邮箱)
- Android 获取手机联系人和手机短信和一个简单的yinyue
- android之获取手机联系人
- Android ContentResolver 获取手机联系人
- android获取手机通讯录联系人
- js如何获取android手机的电话号码和联系人,并且传递给PHP、Java后台