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);
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?
To get to the developer options, open your device's Settings app and navigate to System > Advanced > Developer options > App Compatibility Changes.
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.
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.
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.
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);
}
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With