Opening Camera in Portrait mode using Intent
Asked Answered
S

3

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

Strenuous answered 23/5, 2014 at 5:23 Comment(13)
see this post #10259799Wriggly
this may help you #8516618Indaba
this link is saying that it will work with Camera class while I am using IntentStrenuous
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?Kioto
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);Indaba
I tried this but still opening in Landscape Mode..Strenuous
this may possible if you put android:screenOrientation="portrait" in your manifest.xml like <activity android:name="" android:configChanges="keyboardHidden" android:screenOrientation="portrait"/>Indaba
hi @Vipul my activity has to be only in Landscape modeStrenuous
I am dealing with the same issue right now.You found any efficient solution to this? @NehaShuklaBanded
@Banded nope. not yet.Strenuous
@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.Banded
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);Chery
https://mcmap.net/q/909161/-how-to-set-android-default-camera-app-for-portrait-orientation-only/1288Saccharoid
S
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.
Sericeous answered 4/9, 2016 at 19:14 Comment(0)
C
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.

Civet answered 4/9, 2016 at 23:57 Comment(0)
S
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!!

Stephanestephani answered 7/9, 2016 at 6:44 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.