Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class ManageContacts {
- public static JSONObject getContacts(){
- try {
- JSONObject contacts = new JSONObject();
- JSONArray list = new JSONArray();
- Cursor cur = MyApplication.getAppContext().getContentResolver().query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI,
- new String[] { ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME, ContactsContract.CommonDataKinds.Phone.NUMBER},
- null, null, ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME + " ASC");
- while (cur.moveToNext()) {
- JSONObject contact = new JSONObject();
- String name = cur.getString(cur.getColumnIndex(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME));// for number
- String num = cur.getString(cur.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));// for name
- contact.put("phoneNo", num);
- contact.put("name", name);
- list.put(contact);
- }
- contacts.put("contactsList", list);
- cur.close();
- return contacts;
- } catch (JSONException e) {
- e.printStackTrace();
- }
- return null;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment