Skip to content Skip to sidebar Skip to footer

Get Contact Name?

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 prot

Solution 1:

Try below code for getting contact of specific number

@OverrideprotectedvoidonActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    if (requestCode == REQUEST_CODE_PICK_CONTACTS && resultCode == RESULT_OK) {
        Log.d(TAG, "Response: " + data.toString());
        uriContact = data.getData();

        retrieveContactName();

    }
}

 privatevoidretrieveContactName() {

        StringcontactName=null;

        // querying contact data storeCursorcursor= getContentResolver().query(uriContact, null, null, null, null);

        if (cursor.moveToFirst()) {

            // DISPLAY_NAME = The display name for the contact.// HAS_PHONE_NUMBER =   An indicator of whether this contact has at least one phone number.

            contactName = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));
        }

        cursor.close();

        Log.d(TAG, "Contact Name: " + contactName);

    }

More detail refer below link https://tausiq.wordpress.com/2012/08/23/android-get-contact-details-id-name-phone-photo/

Post a Comment for "Get Contact Name?"