diff options
author | Daniel Gultsch <daniel.gultsch@rwth-aachen.de> | 2014-02-10 03:34:00 +0100 |
---|---|---|
committer | Daniel Gultsch <daniel.gultsch@rwth-aachen.de> | 2014-02-10 03:34:00 +0100 |
commit | 2d0c0e6a4081955b68669c82071a5099e2e1a96e (patch) | |
tree | 229879dfa6611547331849952b220f5fd4b82d54 /src/de/gultsch/chat/utils/PhoneHelper.java | |
parent | c6440aab12460490ef8e9167eac0b515e04f1cdf (diff) |
contact badges
Diffstat (limited to '')
-rw-r--r-- | src/de/gultsch/chat/utils/PhoneHelper.java | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/src/de/gultsch/chat/utils/PhoneHelper.java b/src/de/gultsch/chat/utils/PhoneHelper.java new file mode 100644 index 00000000..f1d491d6 --- /dev/null +++ b/src/de/gultsch/chat/utils/PhoneHelper.java @@ -0,0 +1,65 @@ +package de.gultsch.chat.utils; + +import java.util.ArrayList; +import java.util.Hashtable; + +import android.content.Context; +import android.content.CursorLoader; +import android.content.Loader; +import android.content.Loader.OnLoadCompleteListener; +import android.database.Cursor; +import android.os.Bundle; +import android.provider.ContactsContract; + +public class PhoneHelper { + + public static void loadPhoneContacts(Context context, final OnPhoneContactsLoadedListener listener) { + final Hashtable<String, Bundle> phoneContacts = new Hashtable<String, Bundle>(); + + final String[] PROJECTION = new String[] { + ContactsContract.Data._ID, + ContactsContract.Data.DISPLAY_NAME, + ContactsContract.Data.PHOTO_THUMBNAIL_URI, + ContactsContract.Data.LOOKUP_KEY, + ContactsContract.CommonDataKinds.Im.DATA }; + + final String SELECTION = "(" + ContactsContract.Data.MIMETYPE + "=\"" + + ContactsContract.CommonDataKinds.Im.CONTENT_ITEM_TYPE + + "\") AND (" + ContactsContract.CommonDataKinds.Im.PROTOCOL + + "=\"" + ContactsContract.CommonDataKinds.Im.PROTOCOL_JABBER + + "\")"; + + CursorLoader mCursorLoader = new CursorLoader(context, + ContactsContract.Data.CONTENT_URI, PROJECTION, SELECTION, null, + null); + mCursorLoader.registerListener(0, new OnLoadCompleteListener<Cursor>() { + + @Override + public void onLoadComplete(Loader<Cursor> arg0, Cursor cursor) { + while (cursor.moveToNext()) { + Bundle contact = new Bundle(); + contact.putInt("phoneid", cursor.getInt(cursor + .getColumnIndex(ContactsContract.Data._ID))); + contact.putString( + "displayname", + cursor.getString(cursor + .getColumnIndex(ContactsContract.Data.DISPLAY_NAME))); + contact.putString( + "photouri", + cursor.getString(cursor + .getColumnIndex(ContactsContract.Data.PHOTO_THUMBNAIL_URI))); + contact.putString("lookup",cursor.getString(cursor + .getColumnIndex(ContactsContract.Data.LOOKUP_KEY))); + phoneContacts.put( + cursor.getString(cursor + .getColumnIndex(ContactsContract.CommonDataKinds.Im.DATA)), + contact); + } + if (listener!=null) { + listener.onPhoneContactsLoaded(phoneContacts); + } + } + }); + mCursorLoader.startLoading(); + } +} |