有没有一种方法,同时保持minSDK版本以3比使用了Android 2.1 / 2.2的功能?版本、功能、使用了、方法

由网友(百分之百甜)分享简介:我有一个只使用了Android 1.5的编程项目,但与其他手机和Android 2.2的一些很酷的功能的扩散,我们想支持的功能,而不会失去支持1.5或派生一个新的code基地。是否有可能使用Android SDK?我确实有丑陋的方式一定意义上做到这一点,在保持相同的code的基础,但有一个编译系统建立不同版本的平台,并...

我有一个只使用了Android 1.5的编程项目,但与其他手机和Android 2.2的一些很酷的功能的扩散,我们想支持的功能,而不会失去支持1.5或派生一个新的code基地。是否有可能使用Android SDK?

我确实有丑陋的方式一定意义上做到这一点,在保持相同的code的基础,但有一个编译系统建立不同版本的平台,并保持周围,在得到补充不同的Java文件我们出了构建基于哪个版本的选择。我希望别人已经解决了基于应用程序在市场上的许多版本在多个Android的版本上运行的问题。

解决方案   

我们想支持的功能   又不失1.5或支持   派生一个新的code基地。是吗   可以做到与Android SDK?

当然。该技术已经存在了大约十年左右。

选项#1:使用反射在运行时访问新的类(或现有类的新方法)。 见这里的一个例子。

选项#2:使用有条件类加载,通过创建一个接口加两个实现(一个用于一个较旧的API,一个用于较新的API),并加载正确的实现在运行时。由于较新的实现不会一个较旧的装置上进行装载,事实较新的实现使用的类或方法的较旧的设备缺少不会构成问题。 见这里的一个例子。

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?

AS安装与安卓环境搭建

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 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.

阅读全文

相关推荐

最新文章