Search code examples
androidandroid-file

Filename of recorded audio


I can record the audio. But I want the filename is the current date and time.

Here is my code:

FILE = Environment.getExternalStorageDirectory().getAbsolutePath();
        FILE = FILE + File.separator + "Audio/" +  System.currentTimeMillis() + ".wav";
        System.out.println("Audio path:" + FILE);

Solution

  • Try this

    SimpleDateFormat sdfDate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    Date now = new Date();
    String strDate = sdfDate.format(now);
    FILE = Environment.getExternalStorageDirectory().getAbsolutePath();
    FILE = FILE + File.separator + "Audio/" +  strDate + ".wav";
    System.out.println("Audio path:" + FILE);
    

    You can modify the format as you wish.