5

I know I can set the orientation of the activity in the manifest, but when this activity is calling the MediaStore.ACTION_IMAGE_CAPTURE to open the camera and take a photo, the user can still take photos in landscape mode. Can I lock the orientation of the camera app itself to portrait?

Here is a sample code:

Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(photo));
startActivityForResult(intent, TAKE_PICTURE);

I would like to prevent the user from taking any landscape photos.

Any help would be greatly appreciated.

EDIT: Found another question on the topic that hasn't been answered: How to lock the camera app orientation called through intent in android?

Alex Cohn
  • 56,089
  • 9
  • 113
  • 307
Apostrofix
  • 2,140
  • 8
  • 44
  • 71
  • have you tried setDisplayOrientation method???? – Keyur Lakhani Sep 06 '15 at 19:54
  • @KeyurLakhani I am not sure if I can use it with the `MediaStore.ACTION_IMAGE_CAPTURE` method. – Apostrofix Sep 06 '15 at 19:55
  • 1
    try this using intent i.putExtra(MediaStore.EXTRA_SCREEN_ORIENTATION, ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); – Keyur Lakhani Sep 06 '15 at 19:58
  • @KeyurLakhani Thanks, I tried that but it doesn't have any effect. For the record, the screen orientation on the device is also locked to Portrait, but still the camera app can take photos in landscape. – Apostrofix Sep 06 '15 at 19:59
  • sorry!! for the bad luck but lastly this might be useful http://stackoverflow.com/questions/6813166/set-orientation-of-android-camera-started-with-intent-action-image-capture – Keyur Lakhani Sep 06 '15 at 20:04
  • another option is http://stackoverflow.com/questions/8516118/android-camera-portrait-orientation – Keyur Lakhani Sep 06 '15 at 20:05
  • @KeyurLakhani Thank you for trying to help. I think I'll just find a way to handle the landscape photo. I'll post my solution when I am ready. – Apostrofix Sep 06 '15 at 20:08

1 Answers1

3

After spending some time with it, it seems like it's not possible to lock the orientation to Portrait, when using the Intent MediaStore.ACTION_IMAGE_CAPTURE.

So I decided to implement a custom camera and set the orientation in the code, via the setDisplayOrientation method, as suggested in the comments.

Basically, that's not a solution to the problem, but just another way to "tackle" it, however it suits my case because I was also able to handle the user interface and make some changes in regards to the default interface.

Apostrofix
  • 2,140
  • 8
  • 44
  • 71