Accessing contact' email addresses

Put problem concerning Views, Layouts and other XML-Resources (like AndroidManifest) here.

Accessing contact' email addresses

Postby umair » Tue Mar 17, 2009 7:47 am

Hi!

I'm developing an application in which I need to display user a list of contacts and their email addresses so that user can choose one of them.
I've got some help from Internet and I'm able to display a list of contacts and their number by the following code:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. public class ShowContacts extends ExpandableListActivity implements OnChildClickListener {
  2.     private int mGroupIdColumnIndex;
  3.    
  4.     private String mPhoneNumberProjection[] = new String[] {
  5.             People.Phones._ID, People.NUMBER // CHANGE HERE
  6.     };
  7.  
  8.    
  9.     private ExpandableListAdapter mAdapter;
  10.    
  11.  
  12.     @Override
  13.     public void onCreate(Bundle savedInstanceState) {
  14.         super.onCreate(savedInstanceState);
  15.  
  16.         // Query for people
  17.         Cursor groupCursor = managedQuery(People.CONTENT_URI,
  18.                 new String[] {People._ID, People.NAME}, null, null, null);
  19.  
  20.         // Cache the ID column index
  21.         mGroupIdColumnIndex = groupCursor.getColumnIndexOrThrow(People._ID);
  22.  
  23.         // Set up our adapter
  24.         mAdapter = new MyExpandableListAdapter(groupCursor,
  25.                 this,
  26.                 android.R.layout.simple_expandable_list_item_1,
  27.                 android.R.layout.simple_expandable_list_item_1,
  28.                 new String[] {People.NAME}, // Name for group layouts
  29.                 new int[] {android.R.id.text1},
  30.                 new String[] {People.NUMBER}, // AND CHANGE HERE
  31.                 new int[] {android.R.id.text1});
  32.         setListAdapter(mAdapter);
  33.     }
  34.  
  35.     public class MyExpandableListAdapter extends SimpleCursorTreeAdapter {
  36.  
  37.         public MyExpandableListAdapter(Cursor cursor, Context context, int groupLayout,
  38.                 int childLayout, String[] groupFrom, int[] groupTo, String[] childrenFrom,
  39.                 int[] childrenTo) {
  40.             super(context, cursor, groupLayout, groupFrom, groupTo, childLayout, childrenFrom,
  41.                     childrenTo);
  42.         }
  43.  
  44.         @Override
  45.         protected Cursor getChildrenCursor(Cursor groupCursor) {
  46.             // Given the group, we return a cursor for all the children within that group
  47.  
  48.             // Return a cursor that points to this contact's phone numbers
  49.             Uri.Builder builder = People.CONTENT_URI.buildUpon();
  50.             ContentUris.appendId(builder, groupCursor.getLong(mGroupIdColumnIndex));
  51.             builder.appendEncodedPath(People.Phones.CONTENT_DIRECTORY);
  52.             Uri phoneNumbersUri = builder.build();
  53.  
  54.             return managedQuery(phoneNumbersUri, mPhoneNumberProjection, null, null, null);
  55.         }
  56.     }
  57.    
  58.     @Override
  59.         public boolean onChildClick(android.widget.ExpandableListView parent,
  60.                         View v, int groupPosition, int childPosition, long id) {
  61.                 AlertDialog dialog = new AlertDialog.Builder(ShowContacts.this)
  62.                                 .setMessage(((TextView) v).getText().toString())
  63.                                 .setPositiveButton("OK", null).create();
  64.                 dialog.show();
  65.                 return true;
  66.         }
  67. }
Parsed in 0.041 seconds, using GeSHi 1.0.8.4


What I need now is how to replace numbers by email addresses. What I need to change is People.NUMBER at a couple of places but I'm not able to find any replacement. There is a field called People.PRIMARY_EMAIL_ID but that returns the ID of the email rather than the actuall email.

Kindly guide me what am I missing.

Big thanks in advance!!!
Muhammad Umair
User avatar
umair
Developer
Developer
 
Posts: 28
Joined: Thu Feb 26, 2009 1:00 pm
Location: Lahore, Pakistan

Top

Return to View, Layout & Resource Problems

Who is online

Users browsing this forum: No registered users and 6 guests