如何支持多种Android版本在code? [英] How to support multiple android version in your code?

查看:115
本文介绍了如何支持多种Android版本在code?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以访问Android中的联系人 的android.jar为版本1.6具有People.CONTENT_URI用于调用联系人的相关信息,而在以后的版本中,我们需要有RawContacts.CONTENT_URI API的支持。

Take accessing contacts in android android.jar for versions 1.6 has People.CONTENT_URI for invoking contacts related info whereas in later versions we need to have api support for RawContacts.CONTENT_URI.

同样的事情是真实的,用于访问日历实例作为其URI在Android 2.2的改变。

Same thing is true for accessing calendar for instance as its URI is changed in android 2.2.

有没有来管理所有不同的变化无需增加额外的应用程序或建立单独为每个版本的变化的最佳实践?

Is there a best practice to manage all different changes without adding additional application or build separately for each version of changes?

推荐答案

坦白地说,这是一个痛苦。

Quite Honestly, it's a pain.

我通常只是隔离件code,它是不同的,使用抽象类访问它们。因此从技术上讲创建不同的版本,不同的操作系统。

I usually, just isolate parts of code that are different and access them using abstract classes. So technically creating different version for different OS.

但也有其他方式。最好的一个我见过涉及使用反射。

But there are other ways. The best one i've seen involves using reflection.

这篇关于如何支持多种Android版本在code?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆