tags:

views:

32

answers:

1

When I use the following code in Android 1.6 it displays both phone numbers and contacts but when I use Android 2.2 it does not display phone numbers, it only displays names.

String columns[] = new String[] { People.NAME, People.NUMBER, People._ID };
int tocols[] = new int[] {android.R.id.text1, android.R.id.text2};
Cursor c = managedQuery(People.CONTENT_URI, columns, null, null, null);
SimpleCursorAdapter sca = new SimpleCursorAdapter(this,       
android.R.layout.simple_list_item_2, c, columns, tocols);
setListAdapter(sca);
A: 

Contacts.People is from the old Contacts api (up until 1.6) and is now deprecated. If you want to make sure your data is returning the correct values in android 2.0+ you should switch to the ContactsContract api detailed on developer's site.

http://developer.android.com/resources/articles/contacts.html

You can also encapsulate your code to work with both versions, and there are some samples of how to do this on the android developer's site as well.

EDIT: I found one of the blog posts I noted earlier, its about touch listeners but the principles of splitting your code based on API level are still sound and should work well for implementing contacts provider code across different versions of android.

Since I can't actually post two links in one post (rep is too low) look under the July, 2010 in the on the android developer's blog for "how to have your cupcake and eat it too"

Marloke