I need my personal contact. In Android 4.0 and above, I have my data contact. I tried with ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME, but I got all my contacts without my data contact. Any idea how to get it?
This is my code:
public String getMyName(ContentResolver resolver){
Uri uri = ContactsContract.CommonDataKinds.Phone.CONTENT_URI;
String[] columns = new String[] {ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME,
ContactsContract.CommonDataKinds.Phone.NUMBER};
Cursor people = resolver.query(uri, columns, null, null, null);
try {
int nameIndex = people.getColumnIndex(columns[0]);
int numberIndex = people.getColumnIndex(columns[1]);
people.moveToFirst();
do{
Log.d("Contact result", "Contact name: " + people.getString(nameIndex) + " contact phone: " + people.getString(numberIndex));
} while (people.moveToNext());
}catch (NullPointerException e){
Log.d("Exception", "Null pointer on get personal data");
}
return null;
}
source
share