2012-07-19 60 views
0

Hy大家。 我需要通過聯繫人ID獲取我在android中的電子郵件聯繫人。但它返回一個null值。不要沒有回報,我不知道我失敗的地方。我沒有得到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中沒有得到任何東西。 有人可以幫助我嗎? 感謝

回答

相關問題