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?
Asked
Active
Viewed 214 times
1 Answers
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
-
After tailoring to the new runtime permission scheme this worked perfectly! – hb22 Nov 07 '18 at 00:13