Android camera intent confusion - android

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

Related

How to autmatically capture and save image without press capture button in Android?

I am using Android 5.0 to implement an application which allows to automatically capture and save an image into my phone. Currently, I am using bellow code but it requires press the capture button in Capture UI of my phone. Is it possible to capture and save the image without press the capture button? For example, I just call the function myCaptureandSave(), then the phone will display Capture UI and intermediately capture the image and save, I do not need doing more step.
public void myCaptureandSave() {
String image_path = Environment.getExternalStorageDirectory() +"/"+System.currentTimeMillis()+".jpg";
Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
//File dir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM);
File output = new File(image_path);
cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT,Uri.fromFile(output));
startActivityForResult(cameraIntent, CAMERA_PIC_REQUEST);
}
You have to use Camera Api. Create Service, running in background, which hold reference to this api and current SurfaceTexture, it is necessary, camera will be 'previewing to nowhere'. after that you'll be able to take pictures even if device is locaked
Yes it is possible, but I believe you can't do it using the internal camera (calling the intent). You have to use Camera2 API.
I made a library to use Camera2 API, you can take a look at it if you want:
https://github.com/omaflak/Android-Camera2-Library
In your case, simply pass a dummy SurfaceTexture for the preview and call takePicture().
Hope it will help
how to capture an image in background without using the camera application
i tried with this time ago and with little bit changes i got it.
Hope this helps..

Avoiding the preview after taking pictures with the integrated camera

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 :-(

How to limit the picture size took from IMAGE_CAPTURE intent

I use
Intent intent = new Intent("android.media.action.IMAGE_CAPTURE");
intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(new File(getSomePath()+"temp.jpg")));
//intent.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, 1);
startActivityForResult(intent, 0);
to get a picture and the saved picture returns as full-size.
But I want to get a limited picture, like 800*640, because on different devices I get different sizes, and I don't need that big picture.
I notice that there is a EXTRA_SIZE_LIMIT in MediaStore , but I can't find how to use it, what parameter should be set?
Answering my own question.
Finally I found that's because different manufacturers customize their Rom, including the Camera app, so the best way is not to call the default camera app, instead we can write a activity use hardware.camera to take picture. There are a lot of examples for this around the Internet too.
Unfortunately EXTRA_SIZE_LIMIT used for video limit in bytes.

Why it's so hard taking photos normally on different Android phones?

I made a program whose major function is use API to take photos and store them in the path I gave.
But things don't come out right on different phones comparing to that when I tested on the emulator or phone with Google's origin ROM.
Theoretically. If I gave a path to the Intent, the photo shouldn't appear in the phone's default gallery, but on MOTO Defy the photos were stored in both my path and default image directory. And on Samsung, my app crashes silently when return from the camera Intent. And only on some phones I can bring up menu by pressing the menu button in the Camera Activity. And even some of them saves photo as the size I set in the Camera Activity's setting menu.
I think this is because the manufacturers customized the ROM on their phones so the Camera Activity acts differently.
Anyone know how to avoid this situation? Or is there any other way to take photos not by the intent "android.media.action.IMAGE_CAPTURE" ?
The following is the code how I take photos.
Intent intent = new Intent("android.media.action.IMAGE_CAPTURE");
intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(new File(getpath()+"_.jpg")));
intent.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, 1);
startActivityForResult(intent, 0);
The way that #balban shah offered worked all the same when I tried.
Finally I found that's because different manufacturers customize their Rom, including the Camera app, so the best way is not to call the default camera app, instead we can write a activity use hardware.camera to take picture. There are a lot of examples for this around the Internet too.
try to use this code keep other setting same for photo capture
Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(origImageFile));
startActivityForResult(cameraIntent, 0);

Extend android app

I'd like to create an app that is the same as the default camera app only with one small modification (i.e. video disabled or extra functionality added). How do I do it?
Do I just get the source code of the camera app and modify it or is there a way to extend core components of the Android system?
bizso99,
You can call an Intent from your Activity that is simply the camera sans video functionality like so:
public void imageFromCamera() {
Intent intent = new Intent("android.media.action.IMAGE_CAPTURE");
startActivityForResult(intent, TAKE_PICTURE);
}
This will return a smaller thumbnail version of the image. If you want the full size you need to use the Mediastore.EXTRA_OUTPUT like so:
public void imageFromCamera() {
Intent intent = new Intent("android.media.action.IMAGE_CAPTURE");
mImageFile = new File(pathToStoreImage); //file where image will be stored
mSelectedImagePath = mImageFile.getAbsolutePath(); //path to file where image will be stored
intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(mImageFile));
startActivityForResult(intent, TAKE_PICTURE);
}
Then you can receive the picture in onActivityResult()
Android is open source, so you can download the source for every stock-app in android (not for the google apps like Maps). You can in fact download the most recent original camera app from the android git repo. The building of the apk is only possible if you download the whole android-source. For a overview how to build the android-source, see this howto. You could modify the source for your needs.
I'm quite sure that it is impossible to extend the camera-app without copying the source because there is no plugin-api (or similiar) for the camera-api.

Categories

Resources