android process camera image AFTERwards in OnActivityResult() - android

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.

Related

Open Camera Settings directly from code

I'm developing an app that reads the metadata of images from a device.
One of the conditions is to have activated the geolocation for the photos of your camera to retrieve latitude/longitude from images.
Is it possible to send user (via Intent or something else) to the Camera settings/preferences directly?
I know it's possible to send user to general settings
Intent intent = new Intent(Settings.ACTION_SETTINGS);
startActivity(intent);
But I'm looking for a way to send it directly to the camera settings.
Is it possible to send user (via Intent or something else) to the Camera settings/preferences directly?
No.
I mean the "standard" Camera application of the device. In system settings usually exists a list of your apps and one of them is the Camera application.
No. There are ~2 billion Android devices, comprising thousands of device models. Those ship with hundreds of pre-installed camera apps, let alone the additional camera apps that users might install.
And, of note:
None of those camera apps have to have any sort of settings/preferences screen
None of those camera apps have to offer geolocation

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);

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

Listen to camera actions

Is it possible to receive an intent each time the user take a picture with the device camera?
No, sorry. You can use a FileObserver to monitor the standard photo directory on the device, but that assumes that the app that the user is using is storing photos there.

Keep track of images captured by user

A User takes pictures using camera in his device. My application should keep track of how many photos captured by the user.
I don't want my application to launch any default camera. I want to get count incremented for clicked photos by the user with his device camera.
Since devices having soft button camera not works with CAMERA_BUTTON intent, so is there any other way to get count.
my application should keep track of how many photos captured by the user
In general, that is impossible. You have no ability to spy on arbitrary actions of other applications.
The closest thing is what julian suggested -- use a FileObserver to monitor Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM). However, not all camera applications will store their pictures there.

Categories

Resources