从 Android 内置电话簿获取电子邮件 ID 和姓名?
我正在尝试将 Android 内置电话簿中的姓名和电子邮件 ID 获取到我的页面中,我能够获取姓名、联系人 ID、电话号码。但我无法从 Android 电话簿获取电子邮件 ID。
代码是:
public static final int PICK_CONTACT = 1;
@Override
button.setOnClickListener(new OnClickListener() {
public void onClick(View _view) {
Intent intent = new Intent(Intent.ACTION_PICK,ContactsContract.Contacts.CONTENT_URI);
startActivityForResult(intent, PICK_CONTACT);
}
});
}
@Override
public void onActivityResult(int reqCode, int resCode, Intent data)
{
super.onActivityResult(reqCode, resCode, data);
switch(reqCode) {
case (PICK_CONTACT) : {
if (resCode == Activity.RESULT_OK) {
Uri contactData = data.getData();
Cursor c = managedQuery(contactData, null, null, null, null);
c.moveToFirst();
String name = c.getString(c.getColumnIndexOrThrow(ContactsContract.Contacts.DISPLAY_NAME));
String name1 = c.getString(c.getColumnIndexOrThrow(ContactsContract.Contacts.HAS_PHONE_NUMBER));
String ContactID = c.getString(c.getColumnIndex(ContactsContract.Contacts._ID));
if(Integer.parseInt(name1) == 1){
Cursor emails = getContentResolver().query(ContactsContract.CommonDataKinds.Email.CONTENT_URI,null,
ContactsContract.CommonDataKinds.Email.CONTACT_ID+ " = " + ContactID, null, null);
TextView tv = (TextView)findViewById(R.id.selected_contact_textview);
TextView tv1 = (TextView)findViewById(R.id.selected_email_textview);
tv.setText(name);
tv1.setText(ContactID);
}
}
break;
}
}
在这里我可以从电话簿中获取所选人员的姓名和联系ID。现在我想从电话簿中获取所选人员的姓名和电子邮件 ID。 我怎样才能实现这个目标?
I am trying to get name and email-id from Android inbuilt phone book into my page, I am able to get name, contact ID, phone number. but I am unable to get email ID from the Android phone book.
Code is:
public static final int PICK_CONTACT = 1;
@Override
button.setOnClickListener(new OnClickListener() {
public void onClick(View _view) {
Intent intent = new Intent(Intent.ACTION_PICK,ContactsContract.Contacts.CONTENT_URI);
startActivityForResult(intent, PICK_CONTACT);
}
});
}
@Override
public void onActivityResult(int reqCode, int resCode, Intent data)
{
super.onActivityResult(reqCode, resCode, data);
switch(reqCode) {
case (PICK_CONTACT) : {
if (resCode == Activity.RESULT_OK) {
Uri contactData = data.getData();
Cursor c = managedQuery(contactData, null, null, null, null);
c.moveToFirst();
String name = c.getString(c.getColumnIndexOrThrow(ContactsContract.Contacts.DISPLAY_NAME));
String name1 = c.getString(c.getColumnIndexOrThrow(ContactsContract.Contacts.HAS_PHONE_NUMBER));
String ContactID = c.getString(c.getColumnIndex(ContactsContract.Contacts._ID));
if(Integer.parseInt(name1) == 1){
Cursor emails = getContentResolver().query(ContactsContract.CommonDataKinds.Email.CONTENT_URI,null,
ContactsContract.CommonDataKinds.Email.CONTACT_ID+ " = " + ContactID, null, null);
TextView tv = (TextView)findViewById(R.id.selected_contact_textview);
TextView tv1 = (TextView)findViewById(R.id.selected_email_textview);
tv.setText(name);
tv1.setText(ContactID);
}
}
break;
}
}
Here I am able to get name and contact ID of a selected person from the phonebook. Now I want to get name and email ID of a selected person from phone book.
How can I achieve this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以直接使用联系人 ID 获取联系人的电子邮件地址,如下所示:
You can get the email address of the contact directly using the contact id as follows :