How to get contact number from contactlist in Android?

橙三吉。 提交于 2019-12-30 05:08:21

问题


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;
  }
}

回答1:


I got this answer from the following link

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



来源:https://stackoverflow.com/questions/20044399/how-to-get-contact-number-from-contactlist-in-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!