I am trying to get name and email-id from Android inbuilt phone book into my page, I am able to get name, contact ID, phone number. but I am unable to get email ID from the Android phone book.
Code is:
public static final int PICK_CONTACT = 1;
@Override
button.setOnClickListener(new OnClickListener() {
public void onClick(View _view) {
Intent intent = new Intent(Intent.ACTION_PICK,ContactsContract.Contacts.CONTENT_URI);
startActivityForResult(intent, PICK_CONTACT);
}
});
}
@Override
public void onActivityResult(int reqCode, int resCode, Intent data)
{
super.onActivityResult(reqCode, resCode, data);
switch(reqCode) {
case (PICK_CONTACT) : {
if (resCode == Activity.RESULT_OK) {
Uri contactData = data.getData();
Cursor c = managedQuery(contactData, null, null, null, null);
c.moveToFirst();
String name = c.getString(c.getColumnIndexOrThrow(ContactsContract.Contacts.DISPLAY_NAME));
String name1 = c.getString(c.getColumnIndexOrThrow(ContactsContract.Contacts.HAS_PHONE_NUMBER));
String ContactID = c.getString(c.getColumnIndex(ContactsContract.Contacts._ID));
if(Integer.parseInt(name1) == 1){
Cursor emails = getContentResolver().query(ContactsContract.CommonDataKinds.Email.CONTENT_URI,null,
ContactsContract.CommonDataKinds.Email.CONTACT_ID+ " = " + ContactID, null, null);
TextView tv = (TextView)findViewById(R.id.selected_contact_textview);
TextView tv1 = (TextView)findViewById(R.id.selected_email_textview);
tv.setText(name);
tv1.setText(ContactID);
}
}
break;
}
}
Here I am able to get name and contact ID of a selected person from the phonebook. Now I want to get name and email ID of a selected person from phone book. How can I achieve this?