ALL,
I have following code:
try
{
Intent captureIntent = new Intent( android.provider.MediaStore.ACTION_IMAGE_CAPTURE );
File storage = Environment.getExternalStoragePublicDirectory( Environment.DIRECTORY_PICTURES );
cameraImageFiles = File.createTempFile( "user_photo", ".png", storage );
captureIntent.putExtra( MediaStore.EXTRA_OUTPUT, Uri.fromFile( cameraImageFiles ) );
final Intent galleryIntent = new Intent();
galleryIntent.setType( "image/*" );
galleryIntent.setAction( Intent.ACTION_GET_CONTENT );
Intent photoIntent = Intent.createChooser( galleryIntent, "Select or take a new picture" );
photoIntent.putExtra( Intent.EXTRA_INITIAL_INTENTS, new Intent[] { captureIntent } );
startActivityForResult( photoIntent, CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE );
}
catch( IOException e )
{
Utils.displayErrorDialog( context, e.getMessage() );
}
Every example on the web and here talk about retrieving the image from camera when there is only 1 intent.
Here I have an IntentChooser to select between gallery image or taking the new picture with camera. As far as I understand using this code I will not be able to simply get the image since in "onActivityResult()" I should save the picture to the file - it will not be saved automatically.
Now what I'd like to do is to get the image from the camera shot. I don't really care whether it will be saved or not - I just want a photo.
I know how to get the image from gallery - I have this code and it works. But getting the image from the camera is a puzzle right now.
Thank you.
[EDIT] This is the code I put in the onActivityResult()
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
if( requestCode == CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE )
{
if( resultCode == RESULT_OK )
{
Uri uri = null;
if( data == null )
{
if( cameraImageFiles.exists() )
{
uri = Uri.fromFile( cameraImageFiles );
InputStream input;
try
{
input = getContentResolver().openInputStream( uri );
BitmapFactory.Options opts = new BitmapFactory.Options();
opts.inJustDecodeBounds = true;
bmp = BitmapFactory.decodeStream( input, null, opts );
input.close();
int height = opts.outHeight;
int width = opts.outWidth;
int inSampleSize = 1;
int reqHeight = camera.getHeight();
int reqWidth = camera.getWidth();
if( height > reqHeight || width > reqWidth )
{
int halfHeight = height / 2;
int halfWidth = width / 2;
while( ( halfHeight / inSampleSize ) > reqHeight && ( halfWidth / inSampleSize ) > reqWidth )
inSampleSize *= 2;
}
opts.inSampleSize = inSampleSize;
opts.inJustDecodeBounds = false;
bmp = BitmapFactory.decodeStream( input, null, opts );
camera.setImageBitmap( bmp );
}
catch( FileNotFoundException e )
{
Utils.displayErrorDialog( this, e.getMessage() );
}
catch( IOException e )
{
Utils.displayErrorDialog( this, e.getMessage() );
}
}
photoReady = true;
}
After executing, the code gives null as bmp, so I guess the image is not saved.
[/EDIT]