Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Mobile Development > BOOK: Professional Android 2 Application Development
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: Professional Android 2 Application Development
This is the forum to discuss the Wrox book Professional Android 2 Application Development, 2nd Edition by Reto Meier; ISBN: 978-0-470-56552-0
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Professional Android 2 Application Development section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old October 12th, 2010, 09:24 AM
Registered User
 
Join Date: Oct 2010
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Need help retrieving Contact phone numbers

In Chapter 7, Databases and Content Providers (p.241) Listing 7-19, Accessing the contact Content Provider, the example given to extract the phone number does not work. Instead, this code extracts the contact name and the corresponding contact ID. I haven't been able to figure out how to display the phone number:

Obtain a cursor for every aggregated contact

Code:
Cursor people = getContentResolver().query(ContactsContract.Contacts.CONTENT_URI, null, null, null, null);
				
// Let the Activity manage the cursor life cycle
startManagingCursor(people);
				
int nameIndex = people.getColumnIndexOrThrow(ContactsContract.Contacts.DISPLAY_NAME);
				
int contactIndex = people.getColumnIndexOrThrow(ContactsContract.CommonDataKinds.Phone._ID);

if(people.moveToFirst()) {
	do {
		
		// Extract the phone number
	      String phone = people.getString(contactIndex);
						
              String name = people.getString(nameIndex);
	      Toast.makeText(SampleProvider.this, name + ": " + phone,  Toast.LENGTH_SHORT).show();		
							 	
	} while(people.moveToNext());
	
       stopManagingCursor(people);
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Regular expression for phone numbers [both U.S. an kamii47 BOOK: Beginning Regular Expressions 0 September 8th, 2007 04:08 AM
Removing Blank Spaces in Phone Numbers Brendan Bartley Access 1 April 12th, 2007 12:42 PM
trying to make a custom label for phone numbers... thenoseknows ASP.NET 2.0 Professional 2 August 22nd, 2006 07:07 PM
formatting phone numbers xslt_student XSLT 0 August 7th, 2006 05:10 PM
U.S versus International Phone Numbers bph Access 6 February 19th, 2004 05:15 PM



All times are GMT -4. The time now is 07:17 PM.


Powered by vBulletin®
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.