Android - 当您使用来自较新 API 的方法时,如何在没有 2 个编译的 .apk 文件的情况下支持较旧的 API? [英] Android - How do you support older API's without having 2 compiled .apk files when you use methods from newer API's?

查看:38
本文介绍了Android - 当您使用来自较新 API 的方法时,如何在没有 2 个编译的 .apk 文件的情况下支持较旧的 API?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的应用中实现多点触控.多点触控支持在 API 版本 5 之前不可用.但是,我也希望我的应用程序向后兼容,直到 API 级别 4.有没有办法解决这个问题,除了创建两个单独的 .apk 之外,我删除了来自第 4 级版本的多点触控代码?

I'd would like to implement multi-touch in my app. Multi touch support wasn't available until API version 5. However, I would also like my app to be backwards compatible until API level 4. Is there a way to get around this, other than creating two separate .apk's in which I remove the multi touch code from the level 4 version?

推荐答案

使用来自特定 SDK 版本的功能但仍保持向后兼容的基本方法是创建一个接口来描述您需要的方法,然后实现该接口对于您要定位的不同 SDK 版本.在运行时,您可以根据 Android 版本 (Build.VERSION.SDK) 实例化正确的实现.

The basic way to use features from a specific SDK version, but still remain backwards compatible, is to create an interface describing the methods you need, then implement that interface for the different SDK versions you want to target. At runtime, you instantiate the correct implementation depending on the Android version (Build.VERSION.SDK).

关于多点触控,几个月前在 Android 开发者博客上有一篇很好的文章:如何拥有你的纸杯蛋糕并吃掉它.

With respect to multitouch, there was a good article on the Android Developer's Blog about this a few months ago: How to have your Cupcake and eat it too.

这篇关于Android - 当您使用来自较新 API 的方法时,如何在没有 2 个编译的 .apk 文件的情况下支持较旧的 API?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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