my purpose to retrieve the list of contacts (name, number) is recorded in a json object, to send via web service to the server
then I found the code to visit contacts, and it is good, I test this code
String id, name;
ContentResolver crs = getContentResolver();
Cursor people = crs.query(ContactsContract.Contacts.CONTENT_URI, null,
null, null, null);
String phone = "";
people.moveToPosition(Contexts.getnbContacts());
while (people.moveToNext())
{
id = people.getString(people
.getColumnIndex(ContactsContract.Data._ID));
name = people.getString(people
.getColumnIndex(ContactsContract.Data.DISPLAY_NAME));
if (Integer
.parseInt(people.getString(people
.getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER))) > 0) {
Cursor phones = getContentResolver().query(
ContactsContract.CommonDataKinds.Phone.CONTENT_URI,
null,
ContactsContract.CommonDataKinds.Phone.CONTACT_ID
+ " = " + id, null, null);
while (phones.moveToNext()) {
// pdata =
// phones.getString(phones.getColumnIndex(ContactsContract.CommonDataKinds.Phone.DATA));
phone = phone
+ phones.getString(phones
.getColumnIndex(ContactsContract.CommonDataKinds.Phone.DATA))
+ " and ";
;
}
phones.close();
}
My question is: how to save each contact (name, number) in an array or arraylist ...
each table row designated contact
I think the array type is compatible with json format
so how to copy the contacts in a json object
You can use the below query to retrieve the favourite contacts from Contacts DB
here my code
and need