How to pick the mobile number of a contact using an Intent

Put your problem here if it does not fit any of the other categories.

How to pick the mobile number of a contact using an Intent

Postby cadlg » Wed Aug 19, 2009 7:20 am

Hello friends.

I'm using this code to pick a contact:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.                 Intent i = new Intent(Intent.ACTION_PICK, People.CONTENT_URI);
  2.  
  3.                 startActivityForResult(i, PICK_CONTACT_FROM_LIST);
Parsed in 0.030 seconds, using GeSHi 1.0.8.4


And this to read the phone numbers of the picked contact:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.         protected void onActivityResult(int requestCode, int resultCode, Intent data) {
  2.  
  3.                 super.onActivityResult(requestCode, resultCode, data);
  4.  
  5.                 if (requestCode == PICK_CONTACT_FROM_LIST)
  6.  
  7.                         if (resultCode == RESULT_OK)
  8.  
  9.                         {
  10.  
  11.                                 String [] proj={PhonesColumns.NUMBER,PhonesColumns.TYPE};
  12.  
  13.                                 Cursor cursor = managedQuery(data.getData(),proj,"type=2",null,null);   // mobile  
  14.  
  15.                                 if (cursor.getCount() > 0)
  16.  
  17.                                 {
  18.  
  19.                                         // some code
  20.  
  21.                                 }
  22.  
  23.                         }
  24.  
  25.         }
Parsed in 0.032 seconds, using GeSHi 1.0.8.4


But when the first phone number is not the mobile one (type=2) I get no rows. If I remove the where clause from the query, I get only one phone number (the first one) no matter how many phone numbers the contact has.

Is there something I need to change in the intent or somewhere else to be able to retrieve the mobile phone number when it is not the first phone number of the contact ?

Thanks, and regards.
cadlg
Experienced Developer
Experienced Developer
 
Posts: 84
Joined: Wed Feb 20, 2008 12:33 am
Location: Guatemala

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: No registered users and 15 guests