开发者

How to get EMail address on Android 2.0.1

开发者 https://www.devze.com 2022-12-16 20:59 出处:网络
I am trying to get the emails from a contact on Android (2.0.1). I can´t get the email. The code I am using is:

I am trying to get the emails from a contact on Android (2.0.1). I can´t get the email. The code I am using is:

String columns = new String[]{ContactsContract.Data._ID, 
                              ContactsContract.Data.DATA1,  
                              ContactsContract.Data.DATA2,              
                              ContactsContract.Data.DATA3, 
                              ContactsContract.Data.DATA4,               
                              ContactsContract.Data.DATA5, 
                              ContactsContract.Data.DATA6,               
                              ContactsContract.Data.DATA7, 
                              ContactsContract.Data.DATA8,                
                              ContactsContract.Data.DATA9
                             };

Cursor cursor = contentResolver.query(ContactsContract.Data开发者_如何学运维.CONTENT_URI, columns, null, null, null);

When I try to get the values of the columns, I get null. How can I obtain the emails? Maybe the CONTENT_URI is not correct or tha data is stored in another table and I have to make a join.


I have done this way:

Cursor emailCur = getContentResolver().query( 
                    ContactsContract.CommonDataKinds.Email.CONTENT_URI, 
                    null,
                    ContactsContract.CommonDataKinds.Email.CONTACT_ID + " = ?", 
                    new String[]{id}, null); 
                while (emailCur.moveToNext()) { 
                    String email = emailCur.getString(emailCur.getColumnIndex(ContactsContract.CommonDataKinds.Email.DATA));
                    String emailType = emailCur.getString(emailCur.getColumnIndex(ContactsContract.CommonDataKinds.Email.TYPE)); 
                } 
                emailCur.close();

It is working ok. I hope it can be helpful for another people.


I have done it in this way,

String id = contactData.getLastPathSegment();

Cursor emailsCur = getContentResolver().query(Email.CONTENT_URI, null,
                            Email.CONTACT_ID + " = " + id, null, null);

while (emailsCur.moveToNext()) {               
      String email = emailsCur.getString(emailsCur.getColumnIndex(ContactsContract.CommonDataKinds.Phone.DATA));                     
}
emailsCur.close();

I hope it will help you.


ContactsContract.CommonDataKinds.Email.DATA?

http://developer.android.com/reference/android/provider/ContactsContract.CommonDataKinds.Email.html


I have solved the problem this way:

private static final int SUBACTIVITY_VIEW_CONTACT = 2;
        .
        .
        .
Intent viewContactActivity =  new Intent(Intent.ACTION_VIEW, data.getData());
startActivityForResult(viewContactActivity , SUBACTIVITY_VIEW_CONTACT);        
        .
        .
        .

Then I can see all the emails of the contact on the screen, just as I would have clicked on the contact itself on the Contacts application, but when I click on any email, it appears an "Unsupported Action. The action is not currently supported" screen. Does anybody knows something about it? Thanks.

0

精彩评论

暂无评论...
验证码 换一张
取 消