The requirement is to show camera in portrait mode .
The camera view is displaying properly in all other devices like - Nexus 4 , Nexus 5 , Samsung S3 , Samsung S4 etc .
With NEXUS 6 the camera is displayed as upside down .
Here is how i am setting the camera parameters -
private void setCameraParameters() {
try {
Parameters parameters = mCamera.getParameters();
Camera.CameraInfo camInfo = new Camera.CameraInfo();
Camera.getCameraInfo(mCameraId, camInfo);
int cameraRotationOffset = camInfo.orientation;
System.out.println("Offset :" + cameraRotationOffset);
if (this.getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) {
parameters.set("orientation", "portrait");
mCamera.setDisplayOrientation(90);
Camera.Size size = getBestCameraSize(90,getWidth(),getHeight(),parameters);
if(size==null) {
size = getOptimalPreviewSize(90, getWidth(), getHeight(), parameters);
}
parameters.setPreviewSize(size.width,size.height);
mCamera.setParameters(parameters);
}
} catch (Exception e) {
e.printStackTrace();
}
}
After my experiments i understood that setting display orientation to 270 degrees works fine with Nexus 6 .
Query - How to find out what all devices need the display orientation as 90 and what all devices need the display orintation as 270 ? And how to detect it ?
Use this code to set orientation of your camera as portrait. Its a generic one and should work for all devices:
Source: http://developer.android.com/reference/android/hardware/Camera.html