Opening Camera in Portrait mode using Intent - android

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

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.

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:
Launch this activity from your landscape main app.
This activity has some portrait UI so the user will rotate the phone to read it.
This activity launches the camera, exactly as you are doing it above.
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.

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

Related

Camera Intent (Fresh Start from an emulator), no confirmation after taking one picture

I am just calling a camera intent like this:
Intent camera = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(camera, Constant.CAMERA);
Everything works fine, except when I start run this app for the first time.
I mean, if I wipe out data from my emulator, then start this app then,
The built-in Camera App shows some kind of first user tutorial if I start the camera intent.
After the tutorial, which is , even I take a picture, it does not show a confirmation check box. It keep stay as a built-in camera app and it does not return anything.
However, if I press back button and start the camera intent again, it works fine.
I am not sure how to prevent this kind of tutorial for the first time user.
I am not sure how to prevent this kind of tutorial for the first time user.
That is not possible. The decision of what a particular camera app will do in response to ACTION_IMAGE_CAPTURE is up to the developers of the camera app, not you or me.
Please bear in mind that ACTION_IMAGE_CAPTURE can wind up using any one of hundreds, if not thousands, of possible camera apps. The behavior of each of those camera apps will differ. And, since camera app developers do not seem to test ACTION_IMAGE_CAPTURE very much, you will get odd results like the one that you describe or various other things that you might consider to be a bug.

Android: take camera picture intent remove confirmation dialog

it's possible to disable/remove this photo confirmation dialog:
I need somehow skip this dialog but I still want use an Intent. I found this android: Take camera picture without "save" / "delete" confirmation but I don't want use SurfaceView .
I need somehow skip this dialog but I still want use an Intent.
That is not possible.
There are over 8,000 26,000 Android device models. Across them, there are hundreds of different pre-installed camera apps. Additionally, there are hundreds of additional camera apps that users can install from the Play Store or elsewhere. Any one of them could respond to your ACTION_IMAGE_CAPTURE request.
The protocol for ACTION_IMAGE_CAPTURE does not have an option for "do not show any sort of confirmation dialog". Some camera apps will have such a dialog, others will not. A few apps might have some undocumented Intent extra for controlling that behavior, but most will not.
Either:
Live with the confirmation prompt, where it exists, or
Do not delegate this work to a third-party app, but instead use the camera APIs to take a picture yourself (the SurfaceView approach that you rejected, though it does not necessarily need SurfaceView), or
Do not write the app
Use "android.intent.extra.quickCapture" in Intent.
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
intent.putExtra("android.intent.extra.quickCapture",true);

android process camera image AFTERwards in OnActivityResult()

Per the Google Android camera tutorial I'm using:
new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
or
new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
to open the camera in my app.
Unfortunately, this forces the user to decide beforehand and prevents the user from toggling between pic & vid modes.
My problem is I want the user to go directly to the camera, be able to toggle between picture & video mode,
and then save the image/video accordingly.
Is there some way to:
1) read the Intent data in onActivityResult() and
2) ascertain (AFTER the image has been saved, NOT before) whether it's a pic or a video,
then
3) rename the image to ".jpg" or ".mp4" accordingly?
I've noticed that when I use
new Intent(MediaStore.INTENT_ACTION_VIDEO_CAMERA);
that the camera can then toggle between pic & vid.
But then it won't programmatically save the file.
I want the user to go directly to the camera, be able to toggle between picture & video mode, and then save the image/video accordingly.
That is not going to be possible in general, for the simple reason that you are asking other apps to take pictures and videos on your behalf. The protocol that Android has established for doing that is via the Intent actions that you are presently using. There is no ACTION_CAPTURE_SOMETHING_THAT_THE_USER_THINKS_IS_COOL or the equivalent that allows you to express that you want the user to make a choice after starting the third-party camera activity.
I've noticed that when I use new Intent(MediaStore.INTENT_ACTION_VIDEO_CAMERA);
that the camera can then toggle between pic & vid.
Only for the couple of camera apps that you have tried, out of thousands (pre-installed by device manufacturers, downloaded by users from the Play Store, etc.). The documentation certainly would not imply that behavior would be expected of all camera apps.

how to start my application autiomaticaly in background when user launches a build-in camera on Android

I want to write application on Android that starts in background when user launches a built-in camera (it is important: build-in camera, not an application) and do some actions after user makes a photo.
Is it real? If yes, how to implement this?
I doubt if this is possible. There is no mechanism which android provides that causes a broadcast to the system that Camera has been launched. Plus, you cannot modify the contents shown on the screen as the Camera application is in command. The only way out is to have a MediaScanner and FileObserver to check when a new picture is created in DCIM/Camera/ folder and make your app act accordingly

How to take multiple photos before dismissing camera intent?

I am trying to take multiple photos using the default device camera application launched through an intent (MediaStore.ACTION_IMAGE_CAPTURE). With the devices I am testing with, the camera launches, takes a picture, asks for confirmation, then returns to my activity where I process the result.
I've considered using broadcast receiver callbacks or a content observer; however, I cannot find a way to launch the camera and keep it active until the user is finished. If possible, I wish to avoid developing a custom camera application.
The reason I must do this is because users commonly need to take multiple photos in succession, and on some devices the camera start-up time is upwards of 5 seconds, and the users using the software take 10 - 30 photos consecutively; not only that, but they need control over various camera parameters.
Is there a way to launch the camera intent and only return to my activity once the user exits the camera application?
I discovered through the SDK documentation that there's an alternative intent action for the device camera that launches the camera in still image mode and does not exit until the user is finished with the activity:
Intent intent = new Intent(
MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA);
this.startActivity(intent);
Coupled with a ContentObserver this was exactly what I needed to accomplish.

Categories

Resources