8

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??

Roham Rafii
  • 2,929
  • 7
  • 35
  • 49
Sam
  • 3,453
  • 1
  • 33
  • 57
  • Not sure if that would help at all, but what about checking the orientation is correct after your call by usingWhat about checking the orientation after you have run the code you have currently. You could use maybe theCamera.getParameters().getPictureSize(); and compare the height with the width...? – Matthieu Aug 31 '12 at 07:05

3 Answers3

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.

Daud Arfin
  • 2,499
  • 1
  • 18
  • 37
  • Good idea. Or just ask the user if the proposed rotation is what he wants and allow him to change it if not. – wojciii Aug 30 '12 at 14:32
  • wojci, so that still means we would need to develop the view for landscape to look right holding the phone portrait, as well as properly portrait. also if you try and show the properly portrait view to the user, its probably going to be broken on devices that dont support proper portrait, so youll be showing the user a total mess. also the user shouldnt need to think "oh portrait camera previews dontr work on my phone". just to be clear, we arent talking about a landscape vs portrait interface, we always want the interface to look right while holding the phone portrait. – Sam Aug 30 '12 at 18:25
  • arfin, i don;t quite understand what you mean by a base rotation angle. – Sam Aug 30 '12 at 18:26
  • @Sam here base angle means ask user to select the mode and angle like show the preview and provide a button to rotate the same once they are done and say ok(e.g pressed ok button) you will get the same angle what they have setted and exactly same you needed .. done!! – Daud Arfin Aug 31 '12 at 11:22
  • maybe, after playing with this you can get some really strange effects with the camera, so I'm not really sure a User would understand what they are choosing. – Sam Aug 31 '12 at 23:58
0

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.

dragostis
  • 2,574
  • 2
  • 20
  • 39
  • Hi Dragostis, thank you for your response. Have you found any cases of the SDK7 solution not working on particular devices? (there seem to be some comments floating around to this effect) – Sam Aug 28 '12 at 16:26
  • I'm a game developer and for me, there's not much of a problem other than different screen resolution and ratios which I solved from a single APK. If I were in your situation I'd try to keep it in only one APK and do as much testing as I can. – dragostis Aug 28 '12 at 16:31
  • yes, we have phones to test against, but not all devices unfortunately, and it is supposedly a device dependent thing. – Sam Aug 28 '12 at 16:41
  • I believe what you have done is ok. Try to test on more than 10 device including tablets to be fairly confident on your app. You can also launch a free beta of your app so that people test it. – dragostis Aug 28 '12 at 16:48
  • OK, we have an Xperia X8 which is fine, but there is talk that it doesn't work on the X10, so it doesn't seem that simple for this - seems more of a hardware problem. Unfortunately a beta is not an option for us. – Sam Aug 28 '12 at 16:54
  • Why wouldn't it work on the X10? You can try a service like [this one](https://www.appthwack.com/) online. – dragostis Aug 28 '12 at 16:57
  • no idea, have a read of the thread I linked to in the OP. It seems pretty random. Hence this post and the desire for some kind of clarity on where the bounds of working/not-working lie. – Sam Aug 28 '12 at 17:03
0

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);
    }
}
Ceetn
  • 2,728
  • 2
  • 25
  • 28
  • hi does this not set the orientation of the activity? as far as i knew, the camera has to be set to the same orientation as the activity in order for it to display properly, or you get a weird effect. – Sam Aug 30 '12 at 18:36
  • do you have any more information on how this solution will work? – Sam Sep 01 '12 at 11:56
  • agh, too late, this was potentially quite a useful answer. – Sam Sep 02 '12 at 00:45