5

possible duplicate Stop saving photos using Android native camera

Hello everyone, I am open camera using Intent through like this way

Intent cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(cameraIntent, ACTIVITY_CAMERA);

it fine and give me result perfect but, the problem is this will save the image into sdcard also, how to prevent this to stop the saving image and just use that data into the onActivityResult() method

Community
  • 1
  • 1
Pratik
  • 30,639
  • 18
  • 84
  • 159

1 Answers1

1

I am not sure but try it. It might be help you.

onActivityResult i am taking the Image and then going to store it in to the another bitmap.

See this:

if(resultCode == RESULT_OK && requestCode==TAKE_PHOTO_CODE){
         final File file = getTempFile(this);         
         try {           
             tempBitmap = Media.getBitmap(getContentResolver(), Uri.fromFile(file));
             photoBitmap = Bitmap.createScaledBitmap(tempBitmap, display.getWidth(), display.getHeight(), true);
             takePhotoFromCamera = true;
             // do whatever you want with the bitmap (Resize, Rename, Add To Gallery, etc)         
        } catch (FileNotFoundException e) {           
            e.printStackTrace();         
        } catch (IOException e) {           
            e.printStackTrace();         
        } 
    }

Now, here you can delete the the file after taking it to the bitmap. So it might be not saved to the sdcard.

Try it. Hope it will help you.

or . . .

Use this:

code to get Last picture taken by user:

String[] projection = new String[]
{MediaStore.Images.ImageColumns._ID, MediaStore.Images.ImageColumns.DATA,
 MediaStore.Images.ImageColumns.BUCKET_DISPLAY_NAME,
 DATE_TAKEN, MediaStore.Images.ImageColumns.MIME_TYPE};

final Cursor cursor = managedQuery(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
                                   projection, null, null, DATE_TAKEN + " DESC"); 

After getting that image, delete it. So it will help you.

Enjoy. :))

Guanxi
  • 3,103
  • 21
  • 38
Shreyash Mahajan
  • 23,386
  • 35
  • 116
  • 188
  • Thank you, the code for the last taken picture is userful and solve my problem. – 2red13 Jan 25 '12 at 15:43
  • **CAREFUL**:this is very very dangerous.. in some devices, the pictures we take from our app are not copying to gallery. In that case, if we delete the last taken picture, its returning the picture taken from the camera app, so we end up deleting the wrong picture, not the picture taken from our app. So, the bottom line is, delete the last taken picture from gallery only for the devices which creates the 2nd copy(e.g HTC One M8). – whoami Feb 27 '16 at 11:48