Created
May 26, 2014 07:24
-
-
Save ShinJJang/e1cecb72262c771a6d87 to your computer and use it in GitHub Desktop.
Android to get frequntly contacts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 자주거는(전화 횟수 기준) 4명을 기본으로 가져옴 | |
* 연락한 횟수 내림차순으로 상위 4개에 대해 View를 만듬 | |
**/ | |
private ArrayList<Contact> getFrequntlyContacts() { | |
String selection = Contacts.HAS_PHONE_NUMBER + " == ?"; | |
String[] selectionArgs = new String[]{"1"}; | |
ContentResolver cr = context.getContentResolver(); | |
Cursor cur = cr.query(Contacts.CONTENT_URI, new String[]{Contacts._ID, Contacts.DISPLAY_NAME, Contacts.PHOTO_ID, Contacts.TIMES_CONTACTED, Contacts.HAS_PHONE_NUMBER}, selection, selectionArgs, Contacts.TIMES_CONTACTED + " DESC"); | |
ArrayList<Contact> contact_list = new ArrayList<Contact>(); | |
while (cur.moveToNext() && contact_list.size() < 4) { | |
String id = cur.getString(cur.getColumnIndex(Contacts._ID)); | |
String name = cur.getString(cur.getColumnIndex(Contacts.DISPLAY_NAME)); | |
String phone_number = contactHelper.getPhoneNumberWithContactId(id); | |
int photo_id = cur.getInt(cur.getColumnIndex(Contacts.PHOTO_ID)); | |
Contact contact = new Contact(id, name, phone_number, photo_id); | |
contact_list.add(contact); | |
} | |
cur.close(); | |
return contact_list; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment