0
outputFile = Environment.getExternalStorageDirectory()+ "/Myfolder/"+"/Recording.mp3";

I have been buiding this application for recording audio, and I wanted to have my recordings an unique name with an increment eg. Recording 01.mp3, Recording 02.mp3 etc. Any help would be appreciated.

Kunal Yadav
  • 139
  • 10

3 Answers3

1

You can store the number in SharedPreferences and add that to the filename, here an example of SharedPreferences

SharedPref

Community
  • 1
  • 1
Stefan
  • 2,098
  • 2
  • 18
  • 29
1

You Can Store With Append Device Time With File Name this code will Working fine for your requirement

Please Put This code

outputFile = Environment.getExternalStorageDirectory()+ "/Myfolder/"+"/"+System.currentTimeMillis()+"Recording.mp3";
Riyaz Parasara
  • 154
  • 8
  • 20
1

One way is to use SharedPreferences to store the increment number: First declare SharedPreferences as below:

SharedPreferences prefs = getActivty().getSharedPreferences("fileNumber",MODE.PRIVATE);

Then in your code you can:

int i = prefs.getInt('Number',1); 
outputFile = Environment.getExternalStorageDirectory()+ "/Myfolder/"+"/Recording" + Integer.toString(i) +".mp3";
i++;

And then save the incremented Number:

 SharedPreferences.Editor editor = prefs.edit();
    editor.putInt("Number",i);
    editor.apply();
M.Waqas Pervez
  • 2,492
  • 2
  • 19
  • 33
  • I used it but then, it was overwriting files with only only one name. The iteration did'nt work. So kindly can you tell where should I put the i++ part? – Kunal Yadav Aug 12 '16 at 19:36