Wrox Programmer Forums
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old October 12th, 2010, 08: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

Cursor people = getContentResolver().query(ContactsContract.Contacts.CONTENT_URI, null, null, null, null);
// Let the Activity manage the cursor life cycle
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());

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 03:08 AM
Removing Blank Spaces in Phone Numbers Brendan Bartley Access 1 April 12th, 2007 11:42 AM
trying to make a custom label for phone numbers... thenoseknows ASP.NET 2.0 Professional 2 August 22nd, 2006 06:07 PM
formatting phone numbers xslt_student XSLT 0 August 7th, 2006 04:10 PM
U.S versus International Phone Numbers bph Access 6 February 19th, 2004 05:15 PM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.