How to use contacts API for Android 1.x and 2.x simultaneously?

后端 未结 1 401
盖世英雄少女心
盖世英雄少女心 2021-01-06 15:02

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

相关标签:
1条回答
  • 2021-01-06 15:23

    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.

    0 讨论(0)
提交回复
热议问题