Definitely resolves #3

App is able to retrieve contact's infos from 3rd-party phonebooks.
This commit is contained in:
Alessandro Ferro 2022-10-29 19:54:23 +02:00
parent d958a511b6
commit f19885972c
1 changed files with 6 additions and 3 deletions

View File

@ -102,8 +102,7 @@ public class WhitelistContactsActivity extends AppCompatActivity {
alert.setNeutralButton(R.string.choose_from_contacts,new DialogInterface.OnClickListener() { alert.setNeutralButton(R.string.choose_from_contacts,new DialogInterface.OnClickListener() {
@Override @Override
public void onClick(DialogInterface dialogInterface, int i) { public void onClick(DialogInterface dialogInterface, int i) {
Intent pickContact = new Intent(Intent.ACTION_PICK); Intent pickContact = new Intent(Intent.ACTION_PICK, ContactsContract.CommonDataKinds.Phone.CONTENT_URI);
pickContact.setType(ContactsContract.CommonDataKinds.Phone.CONTENT_TYPE);
startActivityForResult(pickContact, CONTACT_PICK_CODE); startActivityForResult(pickContact, CONTACT_PICK_CODE);
} }
}); });
@ -125,7 +124,11 @@ public class WhitelistContactsActivity extends AppCompatActivity {
super.onActivityResult(requestCode, resultCode, data); super.onActivityResult(requestCode, resultCode, data);
if (resultCode == Activity.RESULT_OK && requestCode == CONTACT_PICK_CODE) { if (resultCode == Activity.RESULT_OK && requestCode == CONTACT_PICK_CODE) {
Uri contactData = data.getData(); 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()) { if (c.moveToFirst()) {
int phoneIndex = c.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER); int phoneIndex = c.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER);
int contactNameIndex = c.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME); int contactNameIndex = c.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME);