I'm trying to get the name and email address from the built-in Android phone book on my page, I can get the name, contact ID, phone number. but I cannot get the email id from the Android phonebook.
The code:
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 can get the name and contact ID of the selected person from the phone book. Now I want to get the name and email address of the selected person from the phone book. How can I achieve this?
user674427
source share