2 slaks SLaks 于 2013.03.29 16:33 提问

如何从电话的联系表中获取email?

我想从手机的联系列表中获取不同的电子邮件地址,比如工作,家庭住址等。我用的下面的代码,但是发现返回的结果是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);

我还需要获取群组,昵称,个人网站。

1个回答

nana4ever
nana4ever   2013.04.02 15:39
已采纳
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();
Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!