I am creating directory in my native application.It is working perfectly in Android 5.0, But In Android 6.0 (Marshmallow) some times it worked and some times not.I am using following code to create new directory.I am saving Video and image file in directory.
public static void createApplicationFolder() {
File f = new File(Environment.getExternalStorageDirectory(), File.separator + Config.VIDEO_COMPRESSOR_APPLICATION_DIR_NAME);
f.mkdirs();
f = new File(Environment.getExternalStorageDirectory(), File.separator + Config.VIDEO_COMPRESSOR_APPLICATION_DIR_NAME + Config.VIDEO_COMPRESSOR_COMPRESSED_VIDEOS_DIR);
f.mkdirs();
f = new File(Environment.getExternalStorageDirectory(), File.separator + Config.VIDEO_COMPRESSOR_APPLICATION_DIR_NAME + Config.VIDEO_COMPRESSOR_TEMP_DIR);
f.mkdirs();
}
In Android Marshmallow you need to ask for dangerous permissions, including STORAGE permission group, in runtime. I know a nice library that can make your life easier, RxPermissions.
You can ask for a permission with few code:
Devices running on Android M, you cant directly write data to storage. you need to ask permission for that.
this link might be helpful
So the permission
WRITE_EXTERNAL_STORAGE
should be asked at run time here.You will also need to override onRequestPermissionsResult() callback method. and you can add the logic here.
Hope it helps :)