0

大家好。我需要通过联系人 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 中什么也没有。有人可以帮助我吗?谢谢

4

1 回答 1

0

像这样尝试 XMPP

https://stackoverflow.com/questions/9885154/how-to-get-images-from-xmpp-in-android-application/10272947#10272947

于 2012-07-19T14:59:01.543 回答