Created
August 12, 2014 05:55
-
-
Save NashLegend/18402a0c3825eee48260 to your computer and use it in GitHub Desktop.
加载最近联系人
This file contains 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
public static void loadStrequent() { | |
ArrayList<Contact> StrequentContacts = new ArrayList<Contact>(); | |
String[] projection = { Contacts._ID, Contacts.DISPLAY_NAME, | |
Contacts.LOOKUP_KEY, Contacts.PHOTO_THUMBNAIL_URI, | |
Contacts.TIMES_CONTACTED, Contacts.LAST_TIME_CONTACTED, | |
Contacts.STARRED, Contacts.PHOTO_ID }; | |
ContentResolver resolver = AppApplication.globalApplication | |
.getContentResolver(); | |
// 显示最近联系人和收藏的联系人 | |
Cursor cursor = resolver.query(Contacts.CONTENT_STREQUENT_URI, | |
projection, null, null, null); | |
// 加载最近联系人,不包括收藏的联系人 | |
//Cursor cursor = resolver.query( | |
// Uri.withAppendedPath(Contacts.CONTENT_URI, "frequent"), | |
// projection, null, null, null); | |
while (cursor.moveToNext()) { | |
Contact contact = new Contact(); | |
long contractID = cursor.getInt(0); | |
String displayName = cursor.getString(1); | |
String lookupKey = cursor.getString(2); | |
String photoUri = cursor.getString(3); | |
int TIMES_CONTACTED = cursor.getInt(4); | |
long LAST_TIME_CONTACTED = cursor.getLong(5); | |
boolean starred = cursor.getInt(6) == 1; | |
contact.setContactId(contractID); | |
contact.setName(displayName); | |
contact.setLookupKey(lookupKey); | |
contact.setPhotoUri(photoUri); | |
contact.setStarred(starred); | |
contact.Times_Contacted = TIMES_CONTACTED; | |
contact.Last_Time_Contacted = LAST_TIME_CONTACTED; | |
StrequentContacts.add(contact); | |
} | |
cursor.close(); | |
AppApplication.StrequentContacts = StrequentContacts; | |
// notify | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment