访问联系人的联系电话
我无法访问联系人的联系电话。 我从互联网上获得了此代码
Intent intent = new Intent(Intent.ACTION_PICK);
intent.setType(ContactsContract.Contacts.CONTENT_TYPE);
startActivityForResult(intent, PICK_CONTACT);
break;
}
}
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
if (requestCode == PICK_CONTACT)
{
Cursor cursor = managedQuery(intent.getData(), null, null, null, null);
cursor.moveToNext();
String contactId = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts._ID));
String name = cursor.getString(cursor.getColumnIndexOrThrow(ContactsContract.Contacts.DISPLAY_NAME));
Toast.makeText(this, "Contect LIST = "+name, Toast.LENGTH_LONG).show();
}
,但它仅显示联系人的姓名。 我想要联系人的电话号码。
I am not able to access the contact number of a contact.
I got this code from internet
Intent intent = new Intent(Intent.ACTION_PICK);
intent.setType(ContactsContract.Contacts.CONTENT_TYPE);
startActivityForResult(intent, PICK_CONTACT);
break;
}
}
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
if (requestCode == PICK_CONTACT)
{
Cursor cursor = managedQuery(intent.getData(), null, null, null, null);
cursor.moveToNext();
String contactId = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts._ID));
String name = cursor.getString(cursor.getColumnIndexOrThrow(ContactsContract.Contacts.DISPLAY_NAME));
Toast.makeText(this, "Contect LIST = "+name, Toast.LENGTH_LONG).show();
}
But it displays only the name of the contact.
I want the contact's phone number.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
查看这篇文章,它有您正在寻找的答案:读取所有联系人的电话号码在安卓中
Check this post out, it has the answer your looking for: Read all contact's phone numbers in android
修改您的代码片段
Modifying your code snippet
要从联系人列表中获取所选联系人的联系人姓名、电话号码和电子邮件,只需添加此代码即可。
还要向您的 AndroidManifest.xml 添加权限它对我有用,希望它也对您有用。
To get contact name, number as well as email of a selected contact from your contact list, then simply add this code.
Also add permissions to your AndroidManifest.xml It works for me, hope it will works for you also.