In my project I put this code to copy mp3 file
here writefile
is the function that copies file.
code is correctly working on devices except Moto G with Android 5.1
p_name = mp_name.concat(".mp3");
InputStream inputStream = null;
try {
inputStream = getResources().openRawResource(mpTrake[id]);
byte[] reader = new byte[inputStream.available()];
while (inputStream.read(reader) != -1) {
}
writefile(reader, "/sdcard/" + mp_name);
Log.i("setring", "success");
} catch (IOException e) {
Log.i("setring", e.getMessage());
} finally {
if (inputStream != null) {
try {
inputStream.close();
} catch (IOException e) {
Log.i("setring", e.getMessage());
}
}
}