开发者

how best to cope with different versions of 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?

many thanks

Ed


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

Edit: 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/


you can get the sdk version with BUILD.VERSION, check How to retrieve the android sdk version?

however, i am wondering what function is runnable on 1.x and not available on 2.x. did you use any of the internal classes?

I really suggest that you fix the function issue, rather than doing different things with different versions, if it can be avoid.


You can read out the OS version of the device.You can have different methods in your app depending on the device OS version, but you can only compile against one SDK version. Therefore, you need to choose the minimum, which at the moment currently is 1.6 (I think 1.5 is rarely used anymore)

see: http://developer.android.com/reference/android/os/Build.VERSION.html

developing for multiple screens / devices: http://developer.android.com/guide/practices/screens_support.html


The Business Card example that comes with the latest Android SDK was a big, big help. I recommend it to those that like me might not be a professional full-time developer. Thanks everyone for your kind input.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜