gpt4 book ai didi

android - 联系人姓名和号码正确时无法获取正确的电子邮件

转载 作者:行者123 更新时间:2023-11-30 03:51:08 25 4
gpt4 key购买 nike

我是 android 的新手,每次我使用下面的代码时,我都想获取联系人列表中现有联系人的电子邮件,但我无法获取联系人的确切电子邮件,而是任何随机电子邮件。请帮助我更正此代码,我将非常感激。

 public void fetchingContacts(Context context) {

Uri uri = ContactsContract.CommonDataKinds.Phone.CONTENT_URI;
ContentResolver cr = context.getContentResolver();
Cursor crsr = cr.query(uri, null, null, null, null);

crsr.moveToFirst();

if (crsr.getCount() > 0) {
while (crsr.moveToNext()) {
ID = crsr
.getString(crsr
.getColumnIndex(ContactsContract.CommonDataKinds.Phone._ID));
id = crsr.getString(crsr.getColumnIndex(BaseColumns._ID));
NAME = crsr
.getString(crsr
.getColumnIndex(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME));
NUMBER = crsr
.getString(crsr
.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));

arylist_contact_id.add(ID);
arylist_all_number.add(NUMBER);
arylist_all_names.add(NAME);
// ////////////



Cursor emailCur = cr.query(
ContactsContract.CommonDataKinds.Email.CONTENT_URI,
null, ContactsContract.CommonDataKinds.Email.CONTACT_ID
+ " = " + id, null, null);

while (emailCur.moveToNext()) {
email = emailCur
.getString(emailCur
.getColumnIndex(ContactsContract.CommonDataKinds.Email.DATA));

Log.v("fetchingEMAIL --- ", email);

}
emailCur.close();


Log.v("IN do while :: name and number ", ID + " , id :" + id
+ " " + NAME + " : " + NUMBER + " : " + email);
}

}
crsr.close();
}

最佳答案

            Cursor emailCur = cr.query(
ContactsContract.CommonDataKinds.Email.CONTENT_URI,
null,
ContactsContract.CommonDataKinds.Email.CONTACT_ID
+ " = ?", new String[] { id }, null);
while (emailCur.moveToNext()) {
String email = emailCur
.getString(emailCur
.getColumnIndex(ContactsContract.CommonDataKinds.Email.ADDRESS));

}
emailCur.close();

以上是有助于正确获取电子邮件的查询,我的 friend ,它对我有用...希望尝试一下。

关于android - 联系人姓名和号码正确时无法获取正确的电子邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14133950/

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