I am getting
open failed:
EACCES (Permission denied)
on the line OutputStream myOutput = new FileOutputStream(outFileName);
I checked the root, and I tried android.permission.WRITE_EXTERNAL_STORAGE
.
How can I fix this problem?
try {
InputStream myInput;
myInput = getAssets().open("XXX.db");
// Path to the just created empty db
String outFileName = "/data/data/XX/databases/"
+ "XXX.db";
// Open the empty db as the output stream
OutputStream myOutput = new FileOutputStream(outFileName);
// Transfer bytes from the inputfile to the outputfile
byte[] buffer = new byte[1024];
int length;
while ((length = myInput.read(buffer)) > 0) {
myOutput.write(buffer, 0, length);
}
// Close the streams
myOutput.flush();
myOutput.close();
myInput.close();
buffer = null;
outFileName = null;
}
catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
The post 6.0 enforcement of storage permissions can be bypassed if you have a rooted device via these adb commands:
I had the same problem on Samsung Galaxy Note 3, running CM 12.1. The issue for me was that i had
and had to use it to take and store user photos. When I tried to load those same photos in ImageLoader i got the
(Permission denied)
error. The solution was to explicitly addsince the above permission only limits the write permission up to API version 18, and with it the read permission.
I have observed this once when running the application inside the emulator. In the emulator settings, you need to specify the size of external storage ("SD Card") properly. By default, the "external storage" field is empty, and that probably means there is no such device and EACCES is thrown even if permissions are granted in the manifest.
I had the same problem... The
<uses-permission
was in the wrong place. This is right:The
uses-permission
tag needs to be outside theapplication
tag.When your application belongs to the system application, it can't access the SD card.
Building on answer by user462990
To be notified when the user responds to the permission request dialog, use this: (code in kotlin)
}