BlackBerryContactManager.java 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. package me.yoqi.deleteallcontacts.utils;
  2. import java.io.UnsupportedEncodingException;
  3. import java.util.ArrayList;
  4. import android.content.ContentResolver;
  5. import android.content.Context;
  6. import android.database.Cursor;
  7. import android.net.Uri;
  8. import android.provider.ContactsContract;
  9. /**
  10. * 黑莓联系人管理,与 android 联系人管理不一样。
  11. *
  12. * @author liuyuqi
  13. *
  14. */
  15. public class BlackBerryContactManager {
  16. ContentResolver resolver;
  17. static String TAG = "me.yoqi.deleteallcontacts.utils.ContactManager";
  18. public BlackBerryContactManager(Context context) {
  19. resolver = context.getContentResolver();
  20. }
  21. /**
  22. * 查询所有联系人
  23. */
  24. public ArrayList<String> getAllContact() {
  25. ArrayList<String> res = new ArrayList<String>();
  26. Uri uri = ContactsContract.Data.CONTENT_URI;
  27. Cursor cursorUser = resolver.query(uri,
  28. new String[] { ContactsContract.CommonDataKinds.Phone._ID,
  29. ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME,
  30. ContactsContract.CommonDataKinds.Phone.RAW_CONTACT_ID },
  31. null, null, null);
  32. while (cursorUser.moveToNext()) {
  33. int id = cursorUser.getInt(0); // 按上面数组的声明顺序获取
  34. String name = cursorUser.getString(1);
  35. int rawContactsId = cursorUser.getInt(2);
  36. res.add("id:" + id + " ,name:" + name + " ,rawContacntsID:" + rawContactsId + "\r\n");
  37. }
  38. return res;
  39. }
  40. public void deleteAllContacts() throws UnsupportedEncodingException, Exception {
  41. // ContactList contactList = (ContactList) PIM.getInstance().openPIMList(PIM.CONTACT_LIST, PIM.READ_WRITE);
  42. // Enumeration e = contactList.items();
  43. // while (e.hasMoreElements()) {
  44. // Contact c = (Contact) e.nextElement();
  45. // contactList.removeContact(c);
  46. // }
  47. }
  48. }