From f19885972c9bd71202c7a88b9b8da1cafbceabc0 Mon Sep 17 00:00:00 2001 From: Alessandro Ferro <49845537+xfarrow@users.noreply.github.com> Date: Sat, 29 Oct 2022 19:54:23 +0200 Subject: [PATCH] Definitely resolves #3 App is able to retrieve contact's infos from 3rd-party phonebooks. --- .../locatemydevice/WhitelistContactsActivity.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/app/src/main/java/com/xfarrow/locatemydevice/WhitelistContactsActivity.java b/src/app/src/main/java/com/xfarrow/locatemydevice/WhitelistContactsActivity.java index 2da551d..9695cf9 100644 --- a/src/app/src/main/java/com/xfarrow/locatemydevice/WhitelistContactsActivity.java +++ b/src/app/src/main/java/com/xfarrow/locatemydevice/WhitelistContactsActivity.java @@ -102,8 +102,7 @@ public class WhitelistContactsActivity extends AppCompatActivity { alert.setNeutralButton(R.string.choose_from_contacts,new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { - Intent pickContact = new Intent(Intent.ACTION_PICK); - pickContact.setType(ContactsContract.CommonDataKinds.Phone.CONTENT_TYPE); + Intent pickContact = new Intent(Intent.ACTION_PICK, ContactsContract.CommonDataKinds.Phone.CONTENT_URI); startActivityForResult(pickContact, CONTACT_PICK_CODE); } }); @@ -125,7 +124,11 @@ public class WhitelistContactsActivity extends AppCompatActivity { super.onActivityResult(requestCode, resultCode, data); if (resultCode == Activity.RESULT_OK && requestCode == CONTACT_PICK_CODE) { Uri contactData = data.getData(); - Cursor c = getContentResolver().query(contactData, null, null, null, null); + String[] projection = { + ContactsContract.CommonDataKinds.Phone.NUMBER, + ContactsContract.Contacts.DISPLAY_NAME + }; + Cursor c = getContentResolver().query(contactData, projection, null, null, null); if (c.moveToFirst()) { int phoneIndex = c.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER); int contactNameIndex = c.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME);