Advertisement
Guest User

Untitled

a guest
Jun 27th, 2016
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.83 KB | None | 0 0
  1. <!--To read contact-->
  2. <uses-permission android:name="android.permission.READ_CONTACTS"/>
  3. /**
  4. * To get the user contact information (Mobile)
  5. *
  6. * @return JSONObject contact information
  7. */
  8. public JSONObject readContact() {
  9. try {
  10. JSONObject contactList = new JSONObject();
  11. ContentResolver contentResolver = mContext.getContentResolver();
  12.  
  13. String[] PHONE_PROJECTION = new String[]{
  14. ContactsContract.RawContacts._ID,
  15. ContactsContract.Contacts.DISPLAY_NAME,
  16. ContactsContract.CommonDataKinds.Phone.NUMBER,
  17. };
  18.  
  19. Cursor people = contentResolver.query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, PHONE_PROJECTION, null, null, null);
  20. if (people != null) {
  21. // Log.e("size ", "" + people.getCount());
  22. while (people.moveToNext()) {
  23. String contactName = people.getString(1);
  24. String phoneNumber = people.getString(2);
  25.  
  26. contactName=contactName.replace(".","u22C5");
  27. contactName=contactName.replace(",","u002C");
  28. contactName=contactName.replace(":","u003B");
  29. contactName=contactName.replace("$","s");
  30. contactName=contactName.replace("@","a");
  31.  
  32. phoneNumber=phoneNumber.replace(".","u22C5");
  33. phoneNumber=phoneNumber.replace(",","u002C");
  34. phoneNumber=phoneNumber.replace(":","u003B");
  35. if (phoneNumber != null)
  36. contactList.put(contactName, phoneNumber);
  37. }
  38. people.close();
  39. }
  40. return contactList;
  41. }catch (Exception e){
  42. //Exception
  43. }
  44. return null;
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement