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 be
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.