如何从Android的联系人列表中获取联系号码?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20044399/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to get contact number from contactlist in Android?
提问by Nitin Karale
I want to get contact number from contact list. In Android application on button i want get number from contact list of phone.
我想从联系人列表中获取联系电话。在按钮上的 Android 应用程序中,我想从电话的联系人列表中获取号码。
Means it click on Select button, & open contact list. it select number, & display in textview.
意味着它点击选择按钮,并打开联系人列表。它选择数字,并在 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;
}
}
采纳答案by Nitin Karale
I got this answer from the following link
我从以下链接得到了这个答案
http://tutorials-android.blogspot.in/2011/11/how-to-call-android-contacts-list.html
http://tutorials-android.blogspot.in/2011/11/how-to-call-android-contacts-list.html