Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Opening Camera in Portrait mode using Intent

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

like image 542
Neha Shukla Avatar asked May 23 '14 05:05

Neha Shukla


People also ask

How do I force an app to open in portrait mode?

Setting the app upWhen on the main screen, under the orientation section, you will see a number of options like 'Auto-rotate OFF', 'Auto-rotate ON', 'Forced Portrait' and 'Forced Landscape'. As the names suggest, you can use these buttons as one-tap shortcuts to toggle the orientation of your device.

How do you open camera through intent and display captured image?

This is done as follows: Intent camera_intent = new Intent(MediaStore. ACTION_IMAGE_CAPTURE); startActivityForResult(camera_intent, pic_id); Now use the onActivityResult() method to get the result, here is the captured image.

How to open camera from Intent in Android?

Intent camera_intent = new Intent(MediaStore. ACTION_IMAGE_CAPTURE); startActivityForResult(camera_intent, pic_id); Now use onActivityResult() method to get the result, here the captured image.

Why does an image captured using camera intent gets rotated?

Most phone cameras are landscape, meaning if you take the photo in portrait, the resulting photos will be rotated 90 degrees. In this case, the camera software should populate the Exif data with the orientation that the photo should be viewed in.


2 Answers

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.
like image 158
happydude Avatar answered Sep 28 '22 01:09

happydude


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.

like image 30
x-code Avatar answered Sep 27 '22 23:09

x-code