Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android API Version Compatibility

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:

2.1:

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

2.2:

camera.setDisplayOrientation(90);

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?

like image 907
aakash Avatar asked Nov 21 '10 07:11

aakash


People also ask

How do I know if APK is compatible?

To get to the developer options, open your device's Settings app and navigate to System > Advanced > Developer options > App Compatibility Changes.

What is API version in Android?

API level is basically the Android version. Instead of using the Android version name (eg 2.0, 2.3, 3.0, etc) an integer number is used. This number is increased with each version. Android 1.6 is API Level 4, Android 2.0 is API Level 5, Android 2.0. 1 is API Level 6, and so on.

How do I know my Android API version?

Tap the "Software Information" option on the About Phone menu. The first entry on the page that loads will be your current Android software version.

What version of Android is API 26?

Android 8.0 (API level 26) includes a new content-centric, Android TV home screen experience, which is available with the Android TV emulator and Nexus Player device image for Android 8.0.


2 Answers

Try:

Camera.Parameters parameters = camera.getParameters();
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.FROYO) {
    parameters.setRotation(90);
    camera.setParameters(parameters);
} else {
    camera.setDisplayOrientation(90);
}
like image 117
André Mion Avatar answered Oct 03 '22 17:10

André Mion


There's no general way to change the camera to orientation to portrait mode prior to v2.2. The set("orientation", "portrait") works on some devices and not on others.

It seemed odd to me as well.

like image 29
Ryan Reeves Avatar answered Oct 03 '22 17:10

Ryan Reeves