moveFile handles absolute paths by not pre-pending anything to them

This commit is contained in:
lenny 2013-03-01 22:11:29 -08:00
parent b8e5aaf754
commit 0ae49ed098

View File

@ -167,13 +167,18 @@ public class AudioPlayer implements OnCompletionListener, OnPreparedListener, On
public void moveFile(String file) { public void moveFile(String file) {
/* this is a hack to save the file as the specified name */ /* this is a hack to save the file as the specified name */
File f = new File(this.tempFile); File f = new File(this.tempFile);
if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
f.renameTo(new File(Environment.getExternalStorageDirectory().getAbsolutePath() if (!file.startsWith("/")) {
+ File.separator + file)); if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
} else { file = Environment.getExternalStorageDirectory().getAbsolutePath() + File.separator + file;
f.renameTo(new File("/data/data/" + handler.cordova.getActivity().getPackageName() + "/cache/" + file)); } else {
file = "/data/data/" + handler.cordova.getActivity().getPackageName() + "/cache/" + file;
}
} }
String logMsg = "renaming " + this.tempFile + " to " + file;
Log.d(LOG_TAG, logMsg);
if (!f.renameTo(new File(file))) Log.e(LOG_TAG, "FAILED " + logMsg);
} }
/** /**