8

I am able to open the device's Camera from my Activity using an Intent as follows:

Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
Uri fileUri = getOutputMediaFileUri();
cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, fileUri);
cameraIntent.putExtra("android.intent.extras.CAMERA_FACING", 1);
startActivityForResult(cameraIntent, CAMERA_REQUEST);

My problem is my Activity is set to Landscape mode, so when the camera is opened, it is also opened in Landscape mode - but I need to open the Camera in Portrait mode only.

So please let me know how can I do this when using an Intent to launch the device's camera.

Thanks...

ban-geoengineering
  • 18,324
  • 27
  • 171
  • 253
Neha Shukla
  • 3,572
  • 5
  • 38
  • 69
  • see this post http://stackoverflow.com/questions/10259299/force-a-camera-to-always-open-in-portrait-mode-in-android – Giru Bhai May 23 '14 at 05:26
  • this may help you http://stackoverflow.com/questions/8516118/android-camera-portrait-orientation – Darsh Patel May 23 '14 at 05:35
  • 1
    this link is saying that it will work with Camera class while I am using Intent – Neha Shukla May 23 '14 at 05:36
  • i.putExtra(MediaStore.EXTRA_SCREEN_ORIENTATION, ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); put this line when you call camera intent and check if its working or not Neha? – Pratik Dasa May 23 '14 at 05:41
  • Intent i = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); i.putExtra(MediaStore.EXTRA_SCREEN_ORIENTATION, ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); i.putExtra(MediaStore.EXTRA_OUTPUT, fileUri); startActivityForResult(i, CAMERA_CODE); – Darsh Patel May 23 '14 at 05:44
  • 1
    I tried this but still opening in Landscape Mode.. – Neha Shukla May 23 '14 at 05:45
  • this may possible if you put android:screenOrientation="portrait" in your manifest.xml like – Darsh Patel May 23 '14 at 05:55
  • hi @Vipul my activity has to be only in Landscape mode – Neha Shukla May 23 '14 at 06:21
  • I am dealing with the same issue right now.You found any efficient solution to this? @NehaShukla – Sash_KP Aug 10 '14 at 19:20
  • @Sash_KP nope. not yet. – Neha Shukla Aug 11 '14 at 04:20
  • @NehaShukla well i tried all the tricks and stuffs to make it work but i too couldn't find an exact solution.However i don't find any odds when i stick the activity to landscape mode only and then when i open camera i can click a picture on landscape as well as portrait.So if it is necessary for you to open camera in portrait only then you have to make a custom camera view using Camera class. – Sash_KP Aug 12 '14 at 16:42
  • I have a similar problem as the OP, the only difference being that I need to force the camera to stay in *landscape* mode. None of these work: `i.putExtra(MediaStore.EXTRA_SCREEN_ORIENTATION, ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);` or `i.putExtra(MediaStore.EXTRA_SCREEN_ORIENTATION, ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE);` or `i.putExtra(MediaStore.EXTRA_SCREEN_ORIENTATION, ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE);` or `i.putExtra(MediaStore.EXTRA_SCREEN_ORIENTATION, ActivityInfo.SCREEN_ORIENTATION_LOCKED);` – ban-geoengineering Sep 02 '16 at 15:21
  • 1
    http://stackoverflow.com/q/25310573/1288 – Bill the Lizard Sep 02 '16 at 15:30

3 Answers3

4

This is an issue with using external apps to handle functionality for you. In theory, apps that accept Intent actions should properly handle the Intent and return the data you are asking for, but in practice there is very little you can do to enforce this behavior...For example, any app can say it handles "image capture," but if you were to pass your Intent to a poorly programmed or malicious app, there is nothing preventing that app from doing something completely different than what you intended, or nothing at all. If you choose to let your app give up control to another app to fulfill certain functionality, you take the risk that whatever app is chosen cannot fulfill that functionality.

In your particular case where you are looking for the ability to add Intent extras, there is no way anyone can answer this question that would apply to all camera apps out there. You would need to find one that supports what you want, figure out how to force it into portrait mode, and then pray that all your users have that particular app installed. The are really very few options to always ensure that your app will take a picture the way you want it to:

  • Create a chooser for your camera Intent and limit the results to only apps that you have tested and know work as intended. If the particular apps are not installed, disable picture taking functionality.
  • Implement image capture yourself.
happydude
  • 3,869
  • 2
  • 23
  • 41
1

You can't force a third party app to launch in any particular orientation. In fact, I notice that whenever I launch the standard Camera app from my (portrait) app, the camera app switches to landscape.

If you set the more modest goal of making sure that the user is holding the phone in portrait when the camera is launched, what you need is a very simple third activity that is portrait only. Then:

  1. Launch this activity from your landscape main app.
  2. This activity has some portrait UI so the user will rotate the phone to read it.
  3. This activity launches the camera, exactly as you are doing it above.
  4. When this activity gets a result, it passes it straight through to your main activity with setResult()

To have any greater level of control, you would have to write your own camera app or require users to use a certain camera that does what you need.

x-code
  • 2,940
  • 1
  • 18
  • 19
1

None of the solutions work.There is nothing wrong with the layouts either.I got it to work by running on a higher version(API10 to API15). Weird!!