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 contact
here my code
public static Map<String, String> getAddressBook(Context context)
{
Map<String, String> result = new HashMap<String, String>();
Cursor cursor = context.getContentResolver().query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null, null, null, null);
while(cursor.moveToNext())
{
int phone_idx = cursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER);
int name_idx = cursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME);
String phone = cursor.getString(phone_idx);
String name = cursor.getString(name_idx);
result.put(name, phone);
}
cursor.close();
return result;
}
and need
<uses-permission android:name="android.permission.READ_CONTACTS"/>
You can use the below query to retrieve the favourite contacts from Contacts DB
Cursor cursor = this.managedQuery(ContactsContract.Contacts.CONTENT_URI, projection, "starred=?",new String[] {"1"}, null);