Nitin Karale
Nitin Karale

Reputation: 797

How to get contact number from contactlist in Android?

I want to get contact number from contact list. In Android application on button i want get number from contact list of phone.

Means it click on Select button, & open contact list. it select number, & display in textview.

Please give me a solution.

Intent intent = new Intent(Intent.ACTION_PICK, ContactsContract.Contacts.CONTENT_URI);
startActivityForResult(intent, PICK_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 =  getContentResolver().query(contactData, null, null, null, null);
        if (c.moveToFirst()) {
          String name = c.getString(c.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));
          // TODO Whatever you want to do with the selected contact name.
        }
      }
      break;
  }
}

Upvotes: 4

Views: 21011

Answers (1)

Nitin Karale
Nitin Karale

Reputation: 797

I got this answer from the following link

http://tutorials-android.blogspot.in/2011/11/how-to-call-android-contacts-list.html

Upvotes: 2

Related Questions