0

I am creating a camera application.Through this I am able to capture the image and storing it into a specific folder.but during this process,the image is getting stored in its default position say sdcard/DCIM/CAMERA.

The file name is current date.when user clicks on save button,then the current date is taken and the filename is generated.So i am not able to detect the file name.

can anybody suggest me that how to access the file name OR how to delete the latest image file programatically.

Narendra Pal
  • 6,474
  • 13
  • 49
  • 85

2 Answers2

0

I think best way is rename new image file with current date based name.You can use this code for rename your files; Immediately, after save file.

File sdcard = Environment.getExternalStorageDirectory();
File from = new File(sdcard,"from.jpg");
File to = new File(sdcard,"to.jpg");
from.renameTo(to);
NrNazifi
  • 1,621
  • 3
  • 25
  • 36
0

I assume you know how to retrieve all files as File objects from the directory to work on. Starting from there use this method to retrieve the last modified file:

public static File getLastModifiedFile( File[] allFiles ) [
    File result = allFiles[1];
    //you cou also use result = null and uncomment the
    //other if-statement. It's probably the first idea but in that case you might
    //return null while here you'll get an exception which makes debugging easier :)

    for( int i = 0; i < allFiles.length; i++ ) {
        if( result.lastModified() < allFiles[i].lastModified() ) {
        //if( result == null || result.lastModified() < allFiles[i].lastModified() ) {
            result = currentFile;
        }
    ]
    return result;
}

Have a look at the File documentation. Here you'll find the explenation of lastModified().

nuala
  • 2,681
  • 4
  • 30
  • 50