I want to get the contact name, but I'm not able to. After looking at this answer, I tried to get the name using family, given, and display, but nothing worked
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == PICK_CONTACT && resultCode == RESULT_OK) {
Uri contactUri = data.getData();
Cursor cursor = getContentResolver().query(contactUri, null, null, null, null);
cursor.moveToFirst(); //Move to first row...I actually dont know why this part is necessary, but I get an error without it...
int NumberColumn = cursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER); //Int column is the column of the numbers
int NameColumn = cursor.getColumnIndex(ContactsContract.CommonDataKinds.StructuredName.GIVEN_NAME);
String contactNumber = cursor.getString(NumberColumn);
String contactName = cursor.getString(NameColumn);
Toast.makeText(MainActivity.this, ""+ contactNumber +"" +contactName, Toast.LENGTH_SHORT).show();
}
/
public void addContact(View v){ //OnClick listener to launch contact picker
Intent intent = new Intent(Intent.ACTION_PICK, ContactsContract.CommonDataKinds.Phone.CONTENT_URI);
startActivityForResult(intent, PICK_CONTACT);
}