I have a very strange problem with accessing storage on some devices. The application works on my test devices (Nexus 4 and 7, Samsung GS5). All my devices are running Android 4.4.2. But I received many emails from users, stating that the application cannot write to the storage (neither internal storage, nor SD card). From the log file received from user reviews, I see that the problem is the following code:
try { if (fStream == null) { fStream = new FileOutputStream(filename, true); } fStream.write(data, 0, bytes); return; } catch (IOException ex) { ex.printStackTrace(); }
It throws an exception in the line fStream = new FileOutputStream (filename, true); when creating a FileOutputStream.
Stack Log:
W/System.err( 8147): Caused by: java.io.FileNotFoundException: /storage/emulated/0/my_folder/test_file_name.png: open failed: EACCES (Permission denied) w/System.err( 8147): at libcore.io.IoBridge.open(IoBridge.java:409) W/System.err( 8147): at java.io.FileOutputStream.<init>(FileOutputStream.java:88) W/System.err( 8147): at java.io.FileOutputStream.<init>(FileOutputStream.java:128) W/System.err( 8147): at myapp.save(SourceFile:515) W/System.err( 8147): ... 8 more W/System.err( 8147): Caused by: libcore.io.ErrnoException: open failed: EACCES (Permission denied) W/System.err( 8147): at libcore.io.Posix.open(Native Method) W/System.err( 8147): at libcore.io.BlockGuardOs.open(BlockGuardOs.java:110) W/System.err( 8147): at libcore.io.IoBridge.open(IoBridge.java:393) W/System.err( 8147): ... 11 more
The following permissions are declared in AndroidManifest.xml:
<uses-sdk android:minSdkVersion="14" android:targetSdkVersion="19"/> <uses-permission android:name="android.permission.INTERNET"/> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/> <uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/> <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
I confirmed that users are using the correct application on the SD card. And what is more strange is that he cannot write to the internal storage. How can this happen if I have read and write permissions? Users say that they do not connect their devices to the PC at this time.
Update
It turns out that I too often call open and close FileOutputStream, which at some point throws a FileNotFoundException. Sounds more like a thread problem.
android filenotfoundexception
user3613696 May 7, '14 at 20:30 2014-05-07 20:30
source share