0

I am trying to deleted camera captured images using below code but images are not deleting i have tried lot but still no result can some one help me please

code:

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

    private void onCaptureImageResult(Intent data) {
    File file = saveImage(this, data);
        if(file !=null){
         file .getCanonicalFile().delete();                
     }
  }


 public File saveImage(Context context, Intent data) {

        File mediaFile = null;
        try {
            Bitmap imgBitmap = (Bitmap) data.getExtras().get("data");
            File sd = Environment.getExternalStorageDirectory();
            File imageFolder = new File(sd.getAbsolutePath() + File.separator +
                    "FOSImages");
            if (!imageFolder.isDirectory()) {
                imageFolder.mkdirs();
            }
            mediaFile = new File(imageFolder + File.separator + "fos_" +
                    System.currentTimeMillis() + ".jpg");
            FileOutputStream fileOutputStream = new FileOutputStream(mediaFile);
            imgBitmap.compress(Bitmap.CompressFormat.JPEG, 90, fileOutputStream);
            fileOutputStream.close();
            return mediaFile;
        } catch (Throwable throwable) {
            throwable.printStackTrace();
        }
        return mediaFile;
    }
AbhiRam
  • 2,033
  • 7
  • 41
  • 94

1 Answers1

0

try this :

File file = saveImage(this, data);
file.delete();
if(file.exists()){
      file.getCanonicalFile().delete();
      if(file.exists()){
           getApplicationContext().deleteFile(file.getName());
      }
}
Nikunj
  • 3,937
  • 19
  • 33