Android的API版本兼容性 [英] Android API Version Compatibility

查看:173
本文介绍了Android的API版本兼容性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想我的应用程序在两个版本的Andr​​oid 2.1和2.2上运行。 在我的应用程序的一个区域,有一个人像风格的相机 - 用于生产肖像相机preVIEW是不同的(据我所知)上的两个操作系统版本。方法如下:

I'd like my app to run on both Android versions 2.1 and 2.2. In one area of my app, there is a portrait-style camera - the process for producing a portrait camera preview is different (as far as I know) on the two OS versions. Here is how:

Camera.Parameters parameters = camera.getParameters();
parameters.set("orientation", "portrait");
camera.setParameters(parameters);

2.2:

camera.setDisplayOrientation(90);

在setDisplayOrientation(int)方法成为API级别可供8(2.2)和,因此,无法在2.1中使用;然而,使用2.1(Camera.Parameters)方法不旋转的preVIEW和图像的正确2.2。

the setDisplayOrientation(int) method became available in API Level 8 (2.2) and, so, cannot be used on 2.1; however, using the 2.1 (Camera.Parameters) method does not rotate the preview and image correctly on 2.2.

这似乎很奇怪,这存在配伍禁忌 - ?有没有做到这一点,让我瞄准两个平台一个比较正确的做法

It seems odd that this incompatibility exists - is there a more correct way to do this that will allow me to target both platforms?

推荐答案

尝试:

Camera.Parameters parameters = camera.getParameters();
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.FROYO) {
    parameters.setRotation(90);
    camera.setParameters(parameters);
} else {
    camera.setDisplayOrientation(90);
}

这篇关于Android的API版本兼容性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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