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.
Related
I am using the code below to start an installed camera app (not developed by me) from a background service in an app I'm working on.
Intent launchIntent = getPackageManager().getLaunchIntentForPackage("com.sec.android.app.camera");
startActivity( launchIntent );
I need to determine if the camera app is done loading and ready to use so I can prompt the camera to take a picture. After the picture is taken, my app will be brought back to the foreground and show a screensaver until the camera is started again or brought back to the foreground to take another picture. Is there a way to verify that the camera app is loaded and ready each time before attempting to send it commands?
For clarity, I'm not asking about how to check this on a camera app specifically. I'm trying to learn how I can start just about any app (not developed by me) and listen for it to be completely loaded and ready.
I am using the code below to start an installed camera app (not developed by me) from a background service
Launching activities from the background is not supported on modern versions of Android.
Also note that many devices will not have that particular package.
I need to determine if the camera app is done loading and ready to use so I can prompt the camera to take a picture
There is no canonical definition of "done loading and ready to use". And, in general, there is no means for you to monitor the operations of another app, for privacy and security reasons.
Also, outside of accessibility services, in general, you have no means of telling a running app to do anything unless it has a specific API for that purpose. Even with accessibility services, I suspect that it will be difficult to come up with an approach that works no matter what the camera app is.
If, from the foreground, you want a camera app to take a picture, use ACTION_IMAGE_CAPTURE. Or, integrate camera functionality directly in your own app, such as via CameraX or other libraries.
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.
I have a button in my app. With an OnClick event to the button I launch the default camera app.
public void startrec(View v) {
Intent intent = new Intent(MediaStore.INTENT_ACTION_VIDEO_CAMERA);
startActivity(intent);
}
This works fine. Now is it possible that the camera starts recording automatically without I have to press the record button in the camera application? So I mean... I press my button in my app -> the camera app starts -> the record starts immediately
How can I do that?
How can I do that?
Record the video yourself, using classes like MediaRecorder.
Your existing code is asking a third-party app to take a video on your behalf. There are hundreds, perhaps thousands, of such apps. The behavior of each of those is up to the developer of those apps. There are no documented extras for your chosen Intent action, let alone one for your desired feature. And even if it existed, not every camera app would honor it.
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!!
I am using some voice recognition on my activity. I have it set to open the camera intent using voice commands, but I'd also like to be able to have it snap the picture via voice. I know I could write this up using the camera object, but I'd rather keep using the intent because it offers more bells and whistles when not using voice.
I'm pretty sure this isn't possible but I'd love to be wrong here. Is there a way to call the capture button on the camera intent programmatically so I can leverage the voice commands to capture my image ie...if I say "take picture"...bam, picture is taken.
Ultimately, I'd also need to be able to programmatically hit the "confirm" button on the intent after the image is captured (or the cancel button), and then have it return to my calling activity.
It is not possible. You can't control other apps. The Intent is just a messages/event. When your app sends some Intent other app could receive it and decide what to do.
I think that the only way is to implement your own camera. By the way there are lots of open-source camera apps. For instance: https://github.com/CyanogenMod/android_packages_apps_Camera.