I am Making an application of camera here on click of button it opens a camera but i want that i should be able to click 5 times and save it on 5 different image view and a
First you need to have controls on your camera. Currently it is open with default mode. So firstly open your camera in surfaceView and implement your own click button. and handle it according to your requirement.
here is a ref. for Custom Camera:
Custom Camera Application
And for displaying images you can pass uri of image one by one ;and when your count is complete display the image where you want.
and for gallery you need to set 5 uri and display it.
It is my experience that there is no easy solution to your problem. Using and Intent to access a camera app, you have two choices related to your issue:
Request, via the intent, to allow the user to take just one picture. In this case, you can provide the file URI where the picture will be stored. To take multiple pictures using this method, the app will have to start the intent multiple times. Each time the user takes a picture, the camera app will exit and return the user to your app. This is probably not the experience you want.
Request, via the intent, to invoke the camera indefinitely. In this mode, the user can take multiple pictures without exiting the camera. However, your app cannot specify where the pictures go. Instead, they will go wherever the camera app decides to store them. You can then find those picture files and use them in your app. I will provide a sketch of how to implement this, below.
You could say there's a third choice, as Neo answered, and write your own camera app. That would certainly be a lot of work if you want the various controls, such as brightness, zoom, etc.!
Background:
First, you need to know about the MediaStore. This is an Android provider that keeps track of all photos (and many other media files and streams) available on your device. Each time the camera app takes a picture, it adds a reference of it to the MediaStore. So, for option 2 above, when the user takes several pictures using the camera app, each picture will be recorded in the MediaStore. This appears to happen immediately, though I don't know of any documentation that supports that. (Thus, there could be a camera app that defers updating MediaStore until some period of time after a picture is taken. Probably not, though.)
Among other things, the MediaStore records the
Method
First, note the current time. You will need this, as you will see below.
long invokeTime = System.currentTimeMillis ();
Register an observer for changes to the MediaStore. Create a subclass of ContentObserver and use this code to register it with MediaStore.
Uri IMAGES_URI = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
getContentResolver().registerContentObserver (IMAGES_URI, true, this);
Your observers subclass will need will need to override the onChange() methods:
@Override public void onChange (boolean selfChage)
{
onChange (selfChage, null);
}
@Override public void onChange (boolean selfChange, Uri uri)
{
listener.onContentChange (selfChange, uri);
}
And, as you can see above, you will need a listener, or some kind of call back to your app, to do something when an onChange() occurs.
In my listener, I save the URIs for the new images in my ArrayList. This is the hard part. onChange() will be called each time a picture is taken. It will be called for any other change to MediaStore as well, so you pay attention only when a new picture was saved. Query the time and file path for the most recent picture:
String[] projection = { MediaStore.Images.Media.DATA, MediaStore.Images.Media.DATE_ADDED };
String selection = null;
String[] selectionArgs = null;
order = MediaStore.Images.ImageColumns.DATE_ADDED + " DESC limit 1";
Cursor cursor = context.getContentResolver().query(
MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
projection,
selection,
selectionArgs,
order);
And fetch the first row
if (cursor.moveToNext())
{
int dateColumn = cursor.getColumnIndex (MediaStore.Images.Media.DATE_ADDED);
int pathColumn = cursor.getColumnIndex (MediaStore.Images.Media.DATA);
dateAddedMillis = cursor.getLong (dateColumn) * 1000;
path = new File (cursor.getString (pathColumn));
}
cursor.close();
If the latest image, as fetched above:
then put it in your ImageView, or whatever you may wish to do with it.
create bitmap from image stored at "path";
Finally, once all this is prepared, invoke the camera:
static private int ACTIVITY_REQUEST_CAMERA = 2;
...
Intent intent = new Intent();
intent.setAction (MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA););
startActivityForResult (intent, ACTIVITY_REQUEST_CAMERA);
When the user exits the camera, be sure to unregister your observer. Otherwise, it will continue to pick up changes to MediaStore from any other app the user happens to use.
The above method is meant to explain the core of this process. In addition, you will need to get the READ_EXTERNAL_STORAGE permission. Also, if the user has an SD card, you may need to ensure that it is mounted. There are probably other considerations.
Nor is it fail safe. It works very well but the user may invoke other apps which create images and you will "capture" those, too. You can probably imagine other failure cases, too.