tags:

views:

578

answers:

1

Mi problem is that I need to implement Contact List in my application for both android 1.5, 1.6 and 2.x.

I did it using the old Contacts API, not ContactsContract because of backwards compatibility with 1.x series. But when displaying my app on 2.x the contact list is not complete. In some devices it's shown as empty, and in some devices it only displays some of the contacts in the device.

I know that using Contacts API on 2.x series it will show only main account contacts, but this is not the case. It looks like only recently updated contacts are shown but that's not the case either.

So the question is: How to correctly implement contact list for both 2.x and 1.x android version?

Thanks in advance

+3  A: 

But when displaying my app on 2.x the contact list is not complete. In some devices it's shown as empty, and in some devices it only displays some of the contacts in the device.

Correct. The old Contacts API only accesses contacts stored solely on the device, not those that were obtained via syncing from other providers. There was also a bug with Android 2.0 where you did not even get the locally-stored contacts, though that was fixed with Android 2.0.1 IIRC.

So the question is: How to correctly implement contact list for both 2.x and 1.x android version?

For minor version-specific changes (e.g., you just need the right Uri), you can just use reflection, as shown in this sample project.

If your needs are more complex, you can take advantage of conditional classloading by creating an interface (or abstract base class) and two implementations, one for each API level, and only use the right one. That is demonstrated in this sample project.

CommonsWare
Thanks for both answers, I'll check that and update when done!
licorna