如何使用联系人API为Android 1.x和2.x同时?如何使用、联系人、API、Android

2023-09-05 09:42:53 作者:旧梦逆心

美的问题是,我需要实现联系人列表在我的应用程序为Android 1.5的,1.6和2.x。

我这样做是使用旧联系 API ,不 ContactsContract 因为与1.x的系列的向后兼容性。但在2.X显示我的应用程序,当联系人列表是不完整的。在一些装置中它显示为空的,并且在一些设备则仅显示某些设备中的触点。

我知道,使用联系 API 2 .X系列它将只显示主帐号接触,但不是这种情况。它看起来像只是在最近更新的联系人显示,但事实并非如此无论是。

所以,问题是:如何正确地实现联系人列表为2.x和1.x的Andr​​oid版本

在此先感谢

解决方案   

但显示我的2.x的应用程序时   联系人列表是不完整的。在一些   装置它示出为空的,而在   一些设备只显示部分   在设备中的联系人。

正确的。旧的联系人API只访问仅存储在设备上的联系人,而不是通过同步从其他供应商获得的那些。也有人对Android 2.0的一个bug,你甚至没有获得本地存储的联系人,尽管这是固定与Android 2.0.1 IIRC。

  

所以,问题是:如何正确   实现这两个2.x的联系人列表   和1.x的Andr​​oid版本?

有关次要版本的具体变化(例如,您只需要正确的乌里),你可以使用反射,如图中的此示例项目。

如果你的需求是比较复杂的,可以利用的条件类加载的通过创建一个接口(或抽象基类)和两个实现,每个API级别,只有使用正确的。这是体现在此示例项目。

Android Studio 3.4.2 之后创建的项目,如何恢复低版本API,AndroidX 如何恢复 support 包

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

解决方案

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.

 
精彩推荐
图片推荐