В моем приложении мне нужно записать видео. Перед началом записи я присваиваю ему имя и каталог. После завершения записи пользователь имеет возможность переименовать свой файл. Я написал следующий код, но, похоже, он не работает.
Когда пользователь вводит имя файла и нажимает кнопку, я сделаю следующее:
private void setFileName(String text) {
String currentFileName = videoURI.substring(videoURI.lastIndexOf("/"), videoURI.length());
currentFileName = currentFileName.substring(1);
Log.i("Current file name", currentFileName);
File directory = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MOVIES), MEDIA_NAME);
File from = new File(directory, "currentFileName");
File to = new File(directory, text.trim() + ".mp4");
from.renameTo(to);
Log.i("Directory is", directory.toString());
Log.i("Default path is", videoURI.toString());
Log.i("From path is", from.toString());
Log.i("To path is", to.toString());
}
Текст: это имя, которое вводится пользователем. Current Filename: имя, которое назначено мной перед записью MEDIA_NAME: имя папки
Logcat показывает это:
05-03 11:56:37.295: I/Current file name(12866): Mania-Karaoke_20120503_115528.mp4
05-03 11:56:37.295: I/Directory is(12866): /mnt/sdcard/Movies/Mania-Karaoke
05-03 11:56:37.295: I/Default path is(12866): /mnt/sdcard/Movies/Mania-Karaoke/Mania-Karaoke_20120503_115528.mp4
05-03 11:56:37.295: I/From path is(12866): /mnt/sdcard/Movies/Mania-Karaoke/currentFileName
05-03 11:56:37.295: I/To path is(12866): /mnt/sdcard/Movies/Mania-Karaoke/hesam.mp4
Любое предложение будет оценено.