tags:

views:

264

answers:

3

Hello, 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 mkae a join.

Really, I don´t know what is the problem.

Thanks

A: 
ContactsContract.CommonDataKinds.Email.DATA?

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

OcuS
Hello OcuS, if I try this: cursor = contentResolver.query( Email.CONTENT_URI /*Data.CONTENT_URI*/, new String[]{ Email._ID, Email.DATA1, Email.DATA2, Email.DATA3, Email.DATA4, Email.DATA5, Email.DATA6, Email.DATA7, Email.DATA8, Email.DATA9}, null, null, null); I get the "home mail" on the Email.Data1, but I want to get all the emails. This is the problem. Thank you for your answer.
android_dev
A: 

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.

android_dev
A: 

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.

android_dev