我的需求是做一個快速撥號界面!list列表顯示所有聯系人Calllog資料!原來的做法在前面的日志中有提到!大概是先查
- Cursor phoneCursor = this.managedQuery(
- ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null, null,
- null, null);
- Cursor phoneCursor = this.managedQuery(
- ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null, null,
- null, null);
再根據號碼來查聯系人
- if(0 < phoneCursor.getCount()){
- phoneCursor.moveToFirst();
-
- // find all contact list
- while (phoneCursor.getPosition() != phoneCursor.getCount()) {
- ContactEntity contactentity = new ContactEntity();
- contactentity.contact_id = phoneCursor
- .getLong(phoneCursor
- .getColumnIndex(ContactsContract.CommonDataKinds.Phone.CONTACT_ID));
- contactentity.contacts_phone_type = phoneCursor
- .getInt(phoneCursor
- .getColumnIndex(ContactsContract.CommonDataKinds.Phone.TYPE));
- contactentity.contacts_phone_number = phoneCursor
- .getString(phoneCursor
- .getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER)).replace(
- "-", "");
-
- contactCursor = this.managedQuery(
- ContactsContract.Contacts.CONTENT_URI, null,
- ContactsContract.Contacts._ID + "="
- + contactentity.contact_id, null, null);
- contactCursor.moveToFirst();
- contactentity.contacts_display_name = contactCursor
- .getString(contactCursor
- .getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME)).replace(
- "-", "");
-
-
- Uri uri = ContentUris.withAppendedId(ContactsContract.Contacts.CONTENT_URI,
- contactentity.contact_id);
- InputStream input = ContactsContract.Contacts.openContactPhotoInputStream(getContentResolver(), uri);
- if(null != input){
- contactentity.contact_phone_bmp = BitmapFactory.decodeStream(input);
- }
-
- // spell name can
- contactentity.spellName = PinYin.getInstance(this).getPinyinString(
- contactentity.contacts_display_name);
-
- Log.i(TAG, "contactentity.contact_id: " + contactentity.contact_id
- + " contactentity.contacts_phone_type: "
- + contactentity.contacts_phone_type
- + " contactentity.contacts_phone_number: "
- + contactentity.contacts_phone_number
- + "contactentity.contacts_display_name: "
- + contactentity.contacts_display_name
- + "contactentity.contact_phone_bmp: "
- + contactentity.contact_phone_bmp);
- phoneCursor.moveToNext();
-
- customArrayList.add(contactentity);
- }
- if(0 < phoneCursor.getCount()){
- phoneCursor.moveToFirst();
-
- // find all contact list
- while (phoneCursor.getPosition() != phoneCursor.getCount()) {
- ContactEntity contactentity = new ContactEntity();
- contactentity.contact_id = phoneCursor
- .getLong(phoneCursor
- .getColumnIndex(ContactsContract.CommonDataKinds.Phone.CONTACT_ID));
- contactentity.contacts_phone_type = phoneCursor
- .getInt(phoneCursor
- .getColumnIndex(ContactsContract.CommonDataKinds.Phone.TYPE));
- contactentity.contacts_phone_number = phoneCursor
- .getString(phoneCursor
- .getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER)).replace(
- "-", "");
-
- contactCursor = this.managedQuery(
- ContactsContract.Contacts.CONTENT_URI, null,
- ContactsContract.Contacts._ID + "="
- + contactentity.contact_id, null, null);
- contactCursor.moveToFirst();
- contactentity.contacts_display_name = contactCursor
- .getString(contactCursor
- .getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME)).replace(
- "-", "");
-
-
- Uri uri = ContentUris.withAppendedId(ContactsContract.Contacts.CONTENT_URI,
- contactentity.contact_id);
- InputStream input = ContactsContract.Contacts.openContactPhotoInputStream(getContentResolver(), uri);
- if(null != input){
- contactentity.contact_phone_bmp = BitmapFactory.decodeStream(input);
- }
-
- // spell name can
- contactentity.spellName = PinYin.getInstance(this).getPinyinString(
- contactentity.contacts_display_name);
-
- Log.i(TAG, "contactentity.contact_id: " + contactentity.contact_id
- + " contactentity.contacts_phone_type: "
- + contactentity.contacts_phone_type
- + " contactentity.contacts_phone_number: "
- + contactentity.contacts_phone_number
- + "contactentity.contacts_display_name: "
- + contactentity.contacts_display_name
- + "contactentity.contact_phone_bmp: "
- + contactentity.contact_phone_bmp);
- phoneCursor.moveToNext();
-
- customArrayList.add(contactentity);
- }
經過測試發現性能消耗主要在這個while循環當中!因為在循環當中在加一個查詢數據庫操作自然慢!