Android mkdirs() not working

你。 提交于 2019-12-05 08:45:40

You are trying to create a directory called myvideo.mp4.

mediaFile = new File(Environment.getExternalStorageDirectory().getAbsolutePath()
                        + "/NewDirectory/myvideo.mp4");
mediaFile.mkdirs();

should be

File(Environment.getExternalStorageDirectory(), "NewDirectory");
mediaFile.mkdirs();

or better

mediaFile = new File(getExternalCacheDir(), "NewDirectory");
mediaFile.mkdirs();

Here you can find the documentation for getExternalCacheDir()

Be aware the from kitkat writing on the root of the sdcard is not allowed anymore.

Edit: the path to the file should be:

mediaFile = new File(getExternalCacheDir(), "NewDirectory");
File file = new File(mediaFile, "myvideo.mp4");
Uri videoUri = Uri.fromFile(file);
Santiago

For create the directory use:

String rootDirectory = Environment.getExternalStorageDirectory().toString();
File myDir = new File(rootDirectory + "/NewDirectory");
myDir.mkdir();

You can save the file with:

recorder.setOutputFile(Environment.getExternalStorageDirectory().toString() + "/NewDirectory/" +fileName);

For find the video for share or reproduce:

File sdcard = Environment.getExternalStorageDirectory();
File directory = new File(sdcard.getAbsolutePath() + "/NewDirectory");
File video = new File(directory, fileName);
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!