gpt4 book ai didi

android - 如何获取联系人电子邮件 ID?

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:48:04 25 4
gpt4 key购买 nike

我有一个电话中所有联系人姓名的 ListView 。我想获取我在 ListView 中单击的联系人的电子邮件 ID(如果联系人有一个)。我该怎么做?

最佳答案

使用以下代码获取所有电子邮件 ID。我检查了代码。它正在工作。

public static void getContactEmails(Context context) {
String emailIdOfContact = null;
int emailType = Email.TYPE_WORK;
String contactName = null;


ContentResolver cr = context.getContentResolver();
Cursor cur = cr.query(ContactsContract.Contacts.CONTENT_URI, null,
null, null, null);
if (cur.getCount() > 0) {
while (cur.moveToNext()) {
String id = cur.getString(cur
.getColumnIndex(BaseColumns._ID));
contactName = cur
.getString(cur
.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));
// Log.i(TAG,"....contact name....." +
// contactName);

cr.query(
ContactsContract.CommonDataKinds.Phone.CONTENT_URI,
null,
ContactsContract.CommonDataKinds.Phone.CONTACT_ID
+ " = ?", new String[] { id }, null);

Cursor emails = cr.query(Email.CONTENT_URI, null,
Email.CONTACT_ID + " = " + id, null, null);
while (emails.moveToNext()) {
emailIdOfContact = emails.getString(emails
.getColumnIndex(Email.DATA));
// Log.i(TAG,"...COntact Name ...."
// + contactName + "...contact Number..."
// + emailIdOfContact);
emailType = emails.getInt(emails
.getColumnIndex(Phone.TYPE));


}
emails.close();

}
}// end of contact name cursor
cur.close();


}

关于android - 如何获取联系人电子邮件 ID?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6152442/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com