Stop saving photos using Android native camera

后端 未结 5 1842
既然无缘
既然无缘 2020-11-29 03:27

I am using native Android camera and save file to my application data folder (/mnt/sdcard/Android/data/com.company.app/files/Pictures/). At the same time anther copy of phot

5条回答
  •  旧巷少年郎
    2020-11-29 04:05

    You can use the following : First we get the last saved image by checking which was the last modified image. Then check if last modified time is in the last few seconds. You may also have to check the exact location of where camera stores the image.

    private boolean deleteLastFromDCIM() {
    
            boolean success = false;
            try {
                File[] images = new File(Environment.getExternalStorageDirectory()
                        + File.separator + "DCIM/Camera").listFiles();
                File latestSavedImage = images[0];
                for (int i = 1; i < images.length; ++i) {
                    if (images[i].lastModified() > latestSavedImage.lastModified()) {
                        latestSavedImage = images[i];
                    }
                }
    
                        // OR JUST Use  success = latestSavedImage.delete();
                success = new File(Environment.getExternalStorageDirectory()
                        + File.separator + "DCIM/Camera/"
                        + latestSavedImage.getAbsoluteFile()).delete();
                return success;
            } catch (Exception e) {
                e.printStackTrace();
                return success;
            }
    
        }
    

提交回复
热议问题