因此,我用MediaRecorder錄製某些內容並將其放置在Android設備中的某處。我如何重命名該文件?這是最接近我的解決方案。點擊按鈕後,沒有任何反應。如何重命名現有文件?
public void nameAlert() {
AlertDialog.Builder nameAlert = new AlertDialog.Builder(this);
nameAlert.setMessage("Name of your recorded file:");
final EditText input = new EditText(this);
nameAlert.setView(input);
nameAlert.setPositiveButton("Enter", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface arg0, int arg1) {
newFileName = input.getText();
String currentFileName = externalStoragePath;
currentFileName = currentFileName.substring(1);
Log.i(storagePath, currentFileName);
File directory = new File (externalStoragePath);
File from = new File (directory, currentFileName);
File to = new File (directory, newFileName + ".mp3");
from.renameTo(to);
}
});
nameAlert.show();
此外,這可能是相關的。
externalStoragePath = Environment.getExternalStorageDirectory().getAbsolutePath();
日誌:
08-02 02:04:03.623: I/(14043): storage/emulated/0
你的代碼是非常簡單,只需它可以得到。 – FabianCook
@SmartLemon有什麼想法可能是錯誤的,但? – Pizzret
Wheres onclick的代碼? – FabianCook