I am new into the android development environment. I want to know if there is a way to overlay an image into the android native camera, so I do not have to program an custom camera, just call the native camera, but into preview an image will be showed. I have tried many ways, but none of them seems to work.
Here is the code I use to shoot the picture and save the image:
Intent cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
File pictureDirectory = new File(Environment.getExternalStorageDirectory() + "/myPics");
String pictureName = getPictureName();
File imageFile = new File(pictureDirectory, pictureName);
Uri pictureUri = Uri.fromFile(imageFile);
cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, pictureUri);
startActivityForResult(cameraIntent, CAMERA_REQUEST);
Something like this face grid, but on top of the native camera:
!https://lh6.ggpht.com/8_x6orazogmW3sU9pnev2EzOalJkKi8ext1qzNTbbHdFCP5W0eKdVJk3KnMijf0nQw=h900
Thank You!
I want to know if there is a way to overlay an image into the android native camera, so I do not have to program an custom camera, just call the native camera, but into preview an image will be showed. Something like this face grid, but on top of the native camera
No.
First, there are thousands of Android device models. These devices will have dozens, if not hundreds, of "android native camera" apps, as many device manufacturers frequently ship a customized camera app.
Second, your code is not invoking an "android native camera" app. Your code is invoking the user's choice of what camera app to use, among the camera apps that the user has installed that support ACTION_IMAGE_CAPTURE. The user can easily choose to use some other camera app, if they prefer that camera app to the one that shipped with their device. So now you have hundreds, if not thousands, of additional camera apps to consider. Any of those could be what a given user is using.
Third, there is no requirement that all camera apps have an identical user interface. The size and position of the camera preview can vary. Not only will they vary between apps, but even the same app might vary the size and position of the camera preview between versions of that app, as apps can and do get updated.
Fourth, you have no good way of determining when any of these camera apps happens to be in the foreground.
Related
I'm working on Android application that capture images and upload this images to a server.
I used intent to open the camera:
val cameraIntent = Intent(MediaStore.ACTION_IMAGE_CAPTURE)
I need to open the camera in landscape orientation, I tried this approach and nothing changed
cameraIntent.putExtra(MediaStore.EXTRA_SCREEN_ORIENTATION, ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE)
Any advice please.
The behavior of the camera app is up to the developers of the camera app. There are hundreds of camera apps, both pre-installed and user-installed. EXTRA_SCREEN_ORIENTATION is not documented as being part of the ACTION_IMAGE_CAPTURE protocol, and I am not aware of any camera apps that would honor it. There is no requirement for any camera app to let callers force a screen orientation.
You could integrate a camera library (CameraX from Google, etc.) and take photos yourself directly in your app. Then, you would be able to control the orientation of your screen (e.g., via android:screenOrientation in the manifest).
When using ACTION_IMAGE_CAPTURE with android Intent:
val intent = Intent(MediaStore.ACTION_IMAGE_CAPTURE)
intent.putExtra(MediaStore.EXTRA_OUTPUT, it.uri)
intentLauncher.launch(intent)
My app opens camera activity as expected, but it seems to be a dumbed-down version of the original camera app. For example on my Samsung S20+ device, I do not get the ability to scan documents when taking pictures, and if I go into settings of launched activity, Intelligent features are disabled and it says that "Intelligent features only work with the rear camera in Photo mode"
If I use INTENT_ACTION_STILL_IMAGE_CAMERA, then all the intelligent features work, but this mode doesn't return me back to my app after taking a picture.
Is there a way to achieve ACTION_IMAGE_CAPTURE with enabled additional camera features?
Can anyone help to remove camera preview of open default camera.
Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(cameraIntent, 100);
That is not possible. There are hundreds, if not thousands, of camera apps that support ACTION_IMAGE_CAPTURE. This includes dozens that are pre-installed ("default camera") on the thousands of different Android device models. Approximately zero of them offer this "feature", because ACTION_IMAGE_CAPTURE does not include that in its protocol.
No, it is not possible using the default camera using ACTION_IMAGE_CAPTURE as you are using. The API simply doesn't support that.
But if you really want to capture images without a preview, you have to do it yourself or use this library. This library does exactly what you are asking for. You can also check the code (it's pretty simple) and implement it yourself.
I want to capture image and upload to server from android client. The supported formats are jpeg,jpg and png. I am not making a custom camera in my application and am calling the camera using below code snippet:-
Intent intent = new Intent();
intent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, imageFileUri);
startActivityForResult(intent, REQUEST_CAMERA);
My doubts :-
Is there any guaranteed format(s) in which the native camera captures the picture?
Is there any way to command the camera to take image in a particular format?
(NB:- I know that I can achieve this by making a custom camera, but I dont want to do that)
Is there any guaranteed format(s) in which the native camera captures the picture?
No. Usually, it will be JPEG, as that is all that many camera apps know about. Possibly, the camera app might examine the MIME type associated with your Uri (e.g., via file extension) and do something based upon that.
But, please understand that there are ~2 billion Android devices, spread across thousands of device models. Those devices ship with hundreds of different pre-installed camera apps, and users can install others from the Play Store and elsewhere. The behavior of camera apps will vary widely, including having bugs.
Is there any way to command the camera to take image in a particular format?
No.
Is there a "secure" way to invoke the android camera with the intent MediaStore.ACTION_IMAGE_CAPTURE to capture a picture?
I am using the following code to take a snapshot from the camera:
Uri tempFile = Uri.fromFile(tempFile()); // returns a temporary stored files that is "Context.MODE_WORLD_WRITEABLE" so that android can put the file in this location
// tempFile looks like: file:///data/data/com.example.myapp/files/temp_picture.jpg
Intent camera = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
camera.putExtra(MediaStore.EXTRA_OUTPUT, tempFile);
startActivityForResult(camera, Constants.REQUESTCODE_PICTURE_RESULT);
After that (returning from camera "RESULT_OK") I am copying the tempFile to the secured application store Context.MODE_PRIVATE and deleting the tempFile.
Everything works fine, the picture is taken and stored on the given Uri. But also the image is placed (in case of my current development device "HTC Sensation") in the galery
from my device (location is /mnt/sdcard/DCIM/100MEDIA/IMAG00XX.jpg). Why is the picture stored twice, I didn't even mention this location in my code? Is this a HTC "feature" or does the android camera store the file twice for media
scanning?
I also tried to get the Bitmap from the camera by omitting the MediaStore.EXTRA_OUTPUT parameter, but with this code I am only getting a thumbsize-picture from the camera (no full resolution).
I read a lot about the android camera, but I have to fetch an image from the camera in a "secured" way (no other app should read the data taken from the camera). I already
thought about implementing my own camera surface to catch a picture, but with this approach I must code a lot of stuff (flash, saturation, effects, zoom...) that the build in camera application already provides. Is it really that hard to take a picture on the android system?
If you want it to be 'secure', build camera functionality in your app. There is no way to be sure what some random camera app that comes pre-installed on a device does. They may be sending pictures to a server somewhere without you knowing. It's not super easy to do reliably, but you can only build the basic functionality. Failing that, require a specific app which you trust for image capture, by making the intent explicit (specify package name). This will, of course, require users to install it first if it is not already there.
I have implemented the camera in the same way as u have done. It creates the image and save it in the folder that i have created.but at the same time it saves image in the gallery as well. I have checked for this if other apps also does that or not. and found that even other apps does that and its not the issue of only HTC have tested it on various devices.even i am thinking how does it works.