如何最好地应对不同的Andr​​oid版本?不同、版本、Andr、oid

2023-09-04 23:49:46 作者:一颗心〤宁缺毋滥

我有一个应用程序工作正常,在安卓1.x中,但不是在安卓2.X 我需要基于Android的应用程序是在(查询联系人)运行的版本做的事情不同。 是有可能有,我可以选择基于Android的版本,一个应用程序中的两个不同的方法的应用程序正在运行呢?

I have an app that works fine in Android 1.x but not in Android 2.x i need to do things different based on the version of Android the app is running on (querying contacts). is it possible to have two separate methods within the one app that i can choose based on the version of Android the app is running on?

非常感谢

推荐答案

使用反射和类加载器。看到这个帖子上的Andr​​oid开发者博客:http://feedproxy.google.com/~r/blogspot/hsDu/~3/9WEwRp2NWlY/how-to-have-your-cupcake-and-eat-it-too.html

Use reflection and class loaders. See this post on the Android developers blog: http://feedproxy.google.com/~r/blogspot/hsDu/~3/9WEwRp2NWlY/how-to-have-your-cupcake-and-eat-it-too.html

编辑: 感谢CommonsWare的指出它同时使用新的和旧的通讯录内容提供商和条件的类加载一个示例项目:的 http://github.com/commonsguy/cw-advandroid/tree/master/Contacts/Spinners/

Thanks to CommonsWare for pointing out a sample project which uses both the new and old contacts content providers and conditional class loading: http://github.com/commonsguy/cw-advandroid/tree/master/Contacts/Spinners/