0

I mean that I don't want to create my own design and instead use the built-in design and view of contact manager that looks clean.

chandan
  • 19
  • 6
  • I think this will help you:- http://stackoverflow.com/questions/9955783/how-do-i-open-contacts-when-i-click-a-button-defined-in-main-xml – gourav sarswa Jun 29 '16 at 06:46
  • Thanks it worked fine. But managedQuery is being deprecated. Replaced it by Cursor c=getContentResolver(). query (contactsData,null,null,null,null));. IT NOW WORKS WITH NO problems. – chandan Jun 29 '16 at 12:09

1 Answers1

0

You can set an Event on Button click by setting an OnClickListener on the Button with the following code, and use Intent to call ContactPicker activity:

button.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
             Intent intent= new Intent(Intent.ACTION_PICK,  Contacts.CONTENT_URI);

    startActivityForResult(intent, PICK_CONTACT);

        }
    });

and in onActivityResult() process the contact uri to load details of contact.

@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 =  managedQuery(contactData, null, null, null, null);
    if (c.moveToFirst()) {
      String name = c.getString(c.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));
      // TODO Fetch other Contact details as you want to use

    }
  }
  break;
}
}
gourav sarswa
  • 325
  • 4
  • 12