Followed Android documentation to write code for launching native camera via intent:
http://developer.android.com/training/camera/photobasics.html
Problem: I am using Andorid Native Camera App for taking pictures from my app and launching via intent as mentioned in above link (MediaStore.ACTION_IMAGE_CAPTURE) and camera is launched successfully. When I click camera button of Native app to take pictures, image preview is mirrored while taking selfie (left image appears right) which selfie user would hate as image preview is not what he clicked.
Second - once image is clicked, it shows image preview and waits for user input for acceptance or rejection of picture.
Once image is accepted, OnStartActivityResult (as mentioned in above link) function receives the call and saves image to gallery. Strange thing here is that: Image gets inverted by 180 degree and then saved which is very weird behaviour.
Finally, two problems here: Image Preview Mirroing issue before user approves and while saving image invert issue (180 degree reverse).
Device: Samsung A6 Edge
Android: 5.1
Camera In Manifest File: Android.hardware.camera2 as Camera is deprecated
Please advise how can i fix above two issues.
Also- I have another doubt: Shall i use android native camera app or write the code using Camera Framework and launch custom camera? My requirement just to click pictures and show preview and save it with correct orientation. After searching a lot, I am doubtful - Can native camera app fix these issues? but your expert advise can help on this.
Any quick support and guidance on this is highly appreciated. Thanks in advance !
Here is the code:
public void triggerCamera() {
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
File imagePath = AppPhotoHelper.getOutputMediaFile();
// Continue only if the File was successfully created
if (imagePath != null) {
takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT,
Uri.fromFile(imagePath));
takePictureIntent.putExtra(MediaStore.EXTRA_SCREEN_ORIENTATION, ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
this.setImagePath(imagePath);
this.startActivityForResult(takePictureIntent, CAMERA_PIC_REQUEST);
}
}
onActivityResult function:
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == CAMERA_PIC_REQUEST) {
if (resultCode == RESULT_OK ) {
//AppPhotoHelper is my class to show image in gallery
AppPhotoHelper.displayInGallery(this.getImagePath(), this);
//Image captured and stored in gallery ... camera invoked for next shot after doing some business processing
this.triggerCamera();
}
else if (resultCode == RESULT_CANCELED) {
return;
}
else {
return;
}
}
}
As mentioned in my post, the native camera app differs from device to device. Did you try your code with another device or emulator? I published a library on github that solves many issues, including the image orientation across a wide variety of devices. Feel free to check it out, run the sample code on your device and check if it works properly for your use case.
Related
I need a camera that allows me take multiple pictures at once and then select one. Others may or may not be stored on the device. I've tried this. I can take multiple images but how to select one and use it in my app? I read the documentation related to camera2 but its hard to understand without any practical example.I also tried these, but an isolated snippet won't help.
Any example related to the use of burst camera would help.
I do not expect a full code, but any directions on how to proceed? Is it possible to display the picture thumbnails as an when they are clicked on the camera screen itself. I'll need to have the bitmap of the image selected.
I can rephrase any part of the question if not clear.
Try this
you can Call your second startActivityForResult() from the onActivityResult() you get from your first startActivityForResult().
like this by this code you can get 10 pic
public int PIC_CODE=0;
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == CAMERA_REQUEST && resultCode == Activity.RESULT_OK) {
// get new image here like this
if(PIC_CODE<10){
// add new requset of picture like this
Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(cameraIntent, CAMERA_REQUEST);
PIC_CODE++;
}
}
You have to implement your own camera to take multiple pictures. Create a class with surface view and implements SurfaceView.Callback. Please check out my library which will implement the same.
https://github.com/SripadRaj/BurstCamera
I'm using different tab, almost the sames.
In my app, I want to take picture with the camera with this code
public void takePicture(View v) {
imageFilePath = file_path + "/" + "Photo_" + idFiche + ".png";
File imageFile = new File(imageFilePath);
Uri imageFileUri = Uri.fromFile(imageFile);
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, imageFileUri);
startActivityForResult(takePictureIntent, REQUEST_CODE_PICTURE);
}
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
InputStream stream = null;
if (requestCode == REQUEST_CODE_PICTURE && resultCode == Activity.RESULT_OK) {
//blablabla
}
}
It works well for some tab, but with others, it's impossible to click on the activation button of the photo app to save the picture, as indicated in below picture with the red border.
I think the camera app is wrong, even if I can take picture from the device directly (not from my app), but how to solve it? Can I delete the picture app and use another app with the same code? Or launch a specific app through new intent???
Thank for your help
I think the camera app is wrong
Most likely. Many camera apps seem to go through little testing of ACTION_IMAGE_CAPTURE.
how to solve it?
Stop using ACTION_IMAGE_CAPTURE. Use the camera APIs directly or through a third-party library.
Can I delete the picture app
If by "the picture app", you mean "the camera app", it is likely that the camera app is pre-installed and cannot be uninstalled. Plus, the user may not appreciate you attempting to uninstall their camera app.
and use another app with the same code?
Your code will already give the user a choice of camera apps, if there is more than one that supports ACTION_IMAGE_CAPTURE installed on the device.
Or launch a specific app through new intent?
It is highly unlikely that your desired "specific app" exists on the device.
I want to take a photo with the camera app which is default on the device. After taking it I have my own preview on which the user can input a text and accept the picture or refuse it. This already works fine.
My problem is now that some user has activated the preview option in the default camera app. Is there a parameter for the Intent to deactivate the default setting and send the picture directly to my app without a preview? I don't find a documentation for this case...
I start the camera with the following code
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
if (takePictureIntent.resolveActivity(this.getPackageManager()) != null) {
this.startActivityForResult(takePictureIntent, MY_CAMERA_REQUEST_CODE);
}
The alternative is to create a own camera in my app. But this is in my opinion a little bit oversized.
Thanks in advance for any help.
There is no possibility to disable the preview programmatically. If something different is needed as the settings of the default camera, an own camera has to be implemented :-(
I have written a simple application in which the user can:
press a button to open the camera application
take pictures with the camera application
Is there any way to disable the shutter sound of the camera from my code?
I currently hold an Orange Nivo phone with Android 4.1.2 version on it.
A secion of my code is:
public void onClick(View v) {
try {
f = createImageFile();
Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
cameraIntent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, Uri.fromFile(f));
startActivityForResult(cameraIntent, CAMERA_REQUEST);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
});
}
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == CAMERA_REQUEST && resultCode == RESULT_OK) {
Bitmap photo = BitmapFactory.decodeFile(f.getAbsolutePath());
Bitmap newphoto = Bitmap.createScaledBitmap(photo, 200, 200, false);
imageView.setImageBitmap(newphoto);
I would appreciate any suggestions on how to achieve this effect.
I know that there are applications on Android store that take pictures without the shutter sound, so i suppose there must be a way to do this without rooting the phone.
The simple answer is: you can not!
The reason is that it is against the law to take a picture without the shutter making sound, this is for privacy concerns. Moreover, as you will notice, you can't take a picture even when your camera preview is not set properly, still for privacy reasons.
At this point you have four options:
Find a way to hack the API
Root the phone and disable the shutter sound
Write your own native code for the camera...but this may be highly dependant on the device you're using it
Use the siplest way that is also the way used by most (if not all) the silent camera
applications in the market. Simply intercept the preview frame via the onPreviewFrame callback from your onClickListener and then save it as an image. The major drawback here is that the maximum preview resolution is far less than the maximum picture resolution so the photo you will take this way will have a fairly low resolution. Indeed if you read the comments on the silent camera apps on the market you will see a lot of people complaining about the resolution of the images not being so high. This is the reason why: they use the trick I exaplained you above.
To conclude, there is no easy way to achieve what you want!
I am working on an app in which i have to click a pic a pic and save it to a specified folder. I am using android.provider.MediaStore.ACTION_IMAGE_CAPTURE in intent to invoke the camera .I am done with coding and my activity is working fine.But now i have a question in my mind that whether i should stick with this code or i should use the code given here.Need your precious suggestions on this topic.
Thanx in advance.
If you want to just click a picture and save it to a specified folder nothing more then You can use Intent and call ACTION_IMAGE_CAPTURE, it easy to let handle on camera activity do your stuff,
And If your application has some serious deep work with camera when you want to modify preview screen size, and all those things,(For this you have to handle all things like to manage camera, and when to release it, check for don't freeze main UI..) then you have to go with the code you suggested...
Choice is yours.....
I suggest you use the code from your link.
Because most of the stock camera apps don't work as expected with Image Capture. For example the Galaxy S2 and most other Samsung and HTC phones give you the picture bytes back and also save the picture in the standard DCIM Folder on SD-Card, if you want it or not.
public void imageFromCamera() {
Intent intent = new Intent("android.media.action.IMAGE_CAPTURE");
if (!Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)){
Log.d(TAG, "No SDCARD");
} else {
mImageFile = new File(Environment.getExternalStorageDirectory()+File.separator+"MyApp",
"PIC"+System.currentTimeMillis()+".jpg");
mTempImagePath = mImageFile.getAbsolutePath();
intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(mImageFile));
startActivityForResult(intent, TAKE_PICTURE);
}
}
this what u r searching i am thinking..