因此,我用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