Android portrait camera reliability

旧城冷巷雨未停 提交于 2020-02-01 02:50:07

问题


I'm developing an app targeted SDK 8 with min SDK 7 that uses a camera view.

Obviously there is this issue of rotating the Camera for portrait that has had a fair amount of discussion already. I currently have the following fix that separates SDK 7 and 8+:

if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.FROYO){
    theCamera.setDisplayOrientation(90);
} else {
    parameters.set("orientation", "portrait");
    parameters.set("rotation",90);
}

Which works on both a 2.1update1 device and an SGS2 I have (running ICS).

My question is, what kind of reliability do these solutions have across devices? I've seen a few solutions to the 'pre-froyo' situation, so I'm dubious of this solution working for all devices. I'm also wondering how well 'setdisplayorientation' is respected on different devices...

I'd be really grateful to hear of other's experience with this.


So some more info: How to set Android camera orientation properly? This explains that these methods work some of the time. So the further question from what point (SDK version) did setDisplayOrientation start working ALL of the time??


回答1:


One weird solution, orientation will not be exactly same for all the devices. It is completely OEM dependent, can vary device to device(I have tried on many devices). You can't fix it simply. Show an Activity with Camera preview on first launch and just ask the user if the proposed rotation is what he wants and allow him to change it if not. Based on user selection, you can handle it.




回答2:


I believe your method works well. The only thing you could possibly do is build different versions of the APK if you ever feel that the app is not device independent.




回答3:


I think checking on the api level is not the correct way of dealing with this problem. Check out the following code for locking the orientation.

public static void lockRotation(final AndroidActivity activity) {
    Display display = ((WindowManager) activity.getSystemService(activity.WINDOW_SERVICE)).getDefaultDisplay();

    // Lock the rotation effect
    // For every 90 degrees we have an other orientation (not only landscape & portrait)
    if (Surface.ROTATION_0 == display.getOrientation()) {
        activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
    } else if (Surface.ROTATION_270 == display.getOrientation()) {
        activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
    } else if (Surface.ROTATION_90 == display.getOrientation()) {
        activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT);
    } else if (Surface.ROTATION_180 == display.getOrientation()) {
        activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE);
    }
}


来源:https://stackoverflow.com/questions/11638250/android-portrait-camera-reliability

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!