开发者

Is there a way to use features in Android 2.1/2.2 while keeping a minSDK version to 3?

I have a project that is just using Android 1.5 for programming, but with the proliferation of other handsets and some cool features in Android 2.2, we'd like to support the features without losing support for 1.5 or forking a new code base. Is it possible to do with Android SDK?

I do have some sense of the "ugly" way to do it, as in keeping the same code base but have a build system that builds different versions for the platforms and keep different Java files around that get added in our out of the 开发者_C百科build based on which version is selected. I'm hoping someone else has solved the problem based on the many versions of apps in the market that run on multiple Android versions.


we'd like to support the features without losing support for 1.5 or forking a new code base. Is it possible to do with Android SDK?

Sure. The techniques have been around for about a decade or so.

Option #1: Use reflection to access new classes (or new methods of existing classes) at runtime. See here for an example.

Option #2: Use conditional class loading, by creating an interface plus two implementations (one for an older API, one for a newer API), and loading the right implementation at runtime. Since the newer implementation will not be loaded on a older device, the fact that the newer implementation uses classes or methods that the older device lacks will not pose a problem. See here for an example.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜