Reputation: 93
I have the next situation: Android 4.1, device doesn't have an external SD card. The following code:
File dir = new File( Environment.getExternalStorageDirectory() );
returns
/storage/sdcard0
Then I try create a file there and get the error
java.io.IOException: open failed: EACCES (Permission denied).
My application has necessary lines in its manifest:
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
In order to resolve this issue I started adb and got file list, this is the fragment:
lrwxrwxrwx root root 2000-01-01 03:12 sdcard -> /storage/sdcard0
lrwxrwxrwx root root 2000-01-01 03:12 sdcard2 -> /storage/sdcard1
d--xr-xr-x system sdcard_r 2000-01-01 03:12 storage
And I don't have permissions to access to /storage/sdcard0 but I can access to /storage/sdcard1 there are dirs:
ABBYY
Alarms
Android
Books
CheetahBrowser
DCIM
Download
SlideIT
etc.
It seems that getExternalStorageDirectory() mere works bad. And it seems weird owing to other applications that could write files in a correct place. What I do wrong?
Update:
getExternalStorageState() returns "removed"
I ignored a result of getExternalStorageDirectory() and set a path manually to "/storage/sdcard1" then everything works good, I can create dirs and files.
Upvotes: 2
Views: 1835
Reputation: 93
I have resolved the problem, it was an exotic one. The device at the beginning had had an external SD card and this card was the "default memory". Then the SD card had been removed but the default memory hadn't been switched to the internal "built-in" storage. As a result the system has been returning an incorrect path to storage until I have corrected the "default memory" setting and the problem disappeared.
Upvotes: 1