views:

131

answers:

1

friends,

i am using folloing code to get addressbook name phone android phone.

btnContacts = (Button) findViewById(R.id.btn_contacts);   
txtContacts = (TextView) findViewById(R.id.txt_contacts);   

btnContacts.setOnClickListener(new OnClickListener() {   

    @Override  
    public void onClick(View arg0) {   
        Intent intent = new Intent(Intent.ACTION_PICK, People.CONTENT_URI);   
        startActivityForResult(intent, PICK_CONTACT);   
    }   
});   

}

@Override
public void onActivityResult(int reqCode, int resultCode, Intent data) {
super.onActivityResult(reqCode, resultCode, data);

switch (reqCode) {   
    case (PICK_CONTACT):   
        if (resultCode == Activity.RESULT_OK) {   
            Uri contactData = data.getData();   
            Cursor c = managedQuery(contactData, null, null, null, null);   
            if (c.moveToFirst()) {   
                String name = c.getString(c.getColumnIndexOrThrow(People.NAME));   
                txtContacts.setText(name);   
            }   
        }   
        break;   
}   

}

now my requirement is to pick email if exisits from the phone book can any one guide me how to achieve this?

any help would be appriciated.

A: 

http://www.codemobiles.com/forum/viewtopic.php?p=1886#1886

UMMA
That worked great, except I had to change the selection arguments from CONTACT_ID to RAW_CONTACT_ID. Using the original code the email address was always from a different contact.I'm running Stock Froyo on my Nexus One using 2.0.1 as my target.
Travis