android中如何取得用户手机的常用联系人(即收藏夹的联系人)

代码:


/**
* 获得收藏夹的联系人
*/
private void getKeepedContacts(){
Cursor cur = getContentResolver().query(  
                ContactsContract.Contacts.CONTENT_URI, null, ContactsContract.Contacts.STARRED + " =  1 " , null, null);  
        startManagingCursor(cur);  
        int num = cur.getCount();
        System.out.println(num + "");
        int count = 0;
        while (cur.moveToNext()) {  
        count ++;
   
            long id = cur.getLong(cur.getColumnIndex("_id"));  
            Cursor pcur = getContentResolver().query(  
                    ContactsContract.CommonDataKinds.Phone.CONTENT_URI,  
                    null,  
                    ContactsContract.CommonDataKinds.Phone.CONTACT_ID + "="  
                            + Long.toString(id), null, null);  
   
            // 处理多个号码的情况  
            String phoneNumbers = "";  
            while (pcur.moveToNext()) {  
                String strPhoneNumber = pcur  
                        .getString(pcur  
                                .getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));  
                phoneNumbers += strPhoneNumber + ":";  
            }  
            phoneNumbers += "\n";  
            pcur.close();
            String name = cur.getString(cur.getColumnIndex("display_name"));
            contactNameList.add(name);
            contactNumList.add(phoneNumbers);
        }  
        cur.close();
}

你可能感兴趣的:(android中如何取得用户手机的常用联系人(即收藏夹的联系人))