大家好。我需要通过联系人 ID 获取我在 android 中的电子邮件联系人。但它返回一个空值。不要返回任何东西,我不知道我在哪里失败了。
public Cursor cursorEmailByContactId(long contactId) {
Uri uri = ContactsContract.CommonDataKinds.Email.CONTENT_URI;
String[] projection = new String[] {
ContactsContract.CommonDataKinds.Email.DATA,
ContactsContract.CommonDataKinds.Email.TYPE,
ContactsContract.CommonDataKinds.Email.LABEL,
};
String where = ContactsContract.CommonDataKinds.Email.CONTACT_ID
+ " = ? ";
String[] whereParams = new String[] { String.valueOf(contactId) };
String order = ContactsContract.CommonDataKinds.Email.IS_PRIMARY
+ " DESC, " + ContactsContract.CommonDataKinds.Email.DATA
+ " COLLATE LOCALIZED ASC";
return ctx.getContentResolver().query(uri, projection, where,
whereParams, order);
}
Cursor cursorEmail = null;
cursorEmail = sds.cursorEmailByContactId(idContacto);
correioElectr = (EditText)findViewById(R.id.sfe_etEmail);
try{
if(cursorEmail.moveToFirst())
do{
sEmail = cursorEmail.getString(cursorEmail.getColumnIndex(ContactsContract.CommonDataKinds.Email.DATA));
}while(cursorEmail.moveToNext());
}finally{
if(cursorEmail != null && !cursorEmail.isClosed())
cursorEmail.close();
}
correioElectr.setText(sEmail);
而且我在 correioElectr editText 中什么也没有。有人可以帮助我吗?谢谢