我想從手機的聯系列表中獲取不同的電子郵件地址,比如工作,家庭住址等。我用的下面的代碼,但是發現返回的結果是0。怎麼回事啊?
Cursor email = cr.query(ContactsContract.CommonDataKinds.Email.CONTENT_URI, null,
Data.CONTACT_ID + " =" + id, null, null);
while (email.moveToNext()) {
emailAdd = email.getString(ContactsContract.CommonDataKinds.Email.TYPE_WORK);
//ContactsContract.CommonDataKinds.Email.TYPE_HOME)
}
Log.v("anim", " emailAdd: " + emailAdd);
我還需要獲取群組,昵稱,個人網站。
Cursor emailCur = cr.query(
ContactsContract.CommonDataKinds.Email.CONTENT_URI,
null,
ContactsContract.CommonDataKinds.Email.CONTACT_ID + " = ?",
new String[]{id}, null);
while (emailCur.moveToNext()) {
// This would allow you get several email addresses
// if the email addresses were stored in an array
String email = emailCur.getString(
emailCur.getColumnIndex(ContactsContract.CommonDataKinds.Email.DATA));
String emailType = emailCur.getString(
emailCur.getColumnIndex(ContactsContract.CommonDataKinds.Email.TYPE));
}
emailCur.close();