I found a solution to my problem thanks to my friend who linked me the same question on stackoverflow.
Basically, to get in touch with a supplier’s phone book search application, we need to start washing ourselves to begin our journey to search.
I used it inside a button that calls this method when a button is clicked.
public void showContactsChooser(final View view){ Intent intent = new Intent(Intent.ACTION_PICK, ContactsContract.Contacts.CONTENT_URI); startActivityForResult(intent, PICK_CONTACT); }
Now we get a screen that shows us all the contacts that we have. We choose one and we return to our application.
To read this contact, I use this method:
@Override public void onActivityResult(int reqCode, int resultCode, Intent data){ super.onActivityResult(reqCode, resultCode, data); switch(reqCode){ case (PICK_CONTACT): if (resultCode == Activity.RESULT_OK){ Uri contactData = data.getData(); Cursor c = getContentResolver().query(contactData, null, null, null, null); if (c.moveToFirst()){ String name = c.getString(c.getColumnIndexOrThrow(ContactsContract.Contacts.DISPLAY_NAME)); Toast.makeText(getApplicationContext(), name, Toast.LENGTH_SHORT).show(); } } } }
And done :)
My knowledge is taken from http://eclipsed4utoo.com/blog/android-open-contacts-activity-return-chosen-contact/ And the author of this is all right.
source share