-1

I've been having difficulty implementing the retrieval of the phone number of a contact whose name matches a given string and then dialing that number. I know this is possible because many existing apps include this feature. How can it be implemented?

hb22
  • 383
  • 1
  • 2
  • 14

1 Answers1

1

this code getting all contacts in phone

Cursor phones = context.getContentResolver().query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null, null, null, null);
    if (phones != null) {
        while (phones.moveToNext()) {
            String name = phones.getString(phones.getColumnIndex(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME));
            String phoneNumber = phones.getString(phones.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
        }
        phones.close();

    }

Compare the variable "name" or "phoneNumber" with your String

and you have add permission "android.permission.READ_CONTACTS"

مهند عطية
  • 1,098
  • 7
  • 10