I am trying to create a directory on the external sdcard in my Samsung S4. Doing something like this,
public void createTestFile(){
File appDir = new File(Environment.getExternalStorageDirectory() + "/external_sd", "TestFile");
appDir.mkdir();
}
does not create a directory on my external sdcard. According to several other StackOverflow posts, and the Samsung developer's forum (http://developer.samsung.com/forum/board/thread/view.do?boardName=GeneralB&messageId=162934&messageNumber=1381&startId=zzzzz~&searchType=TITLE&searchText=sdcard) it should.
Checking the application manifest I have the following permission,
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE">
What am I missing here? This device is rooted and I am running a recent CyanogenMod 12.1 nightly. The permissions for /sdcard, /external_sd, and /extSdCard appear correct.
I've also tried,
File appDir = new File(Environment.getExternalStorageDirectory().getParent() + "/external_sd", "TestFile");
as well as .getAbsolutePath(), and .getPath() with no luck whatsoever. What am I missing here? It's got to be simple...
Update 11/21/2015 7:00pm Tried the following,
public void createTestFile(){
String showPath = Environment.getExternalStorageDirectory().getParent();// "../storage/emulated"
//String finalPath = showPath+"/0"; // "../storage/emulated/0" This works- writes to internal sdcard.
//String finalPath = showPath+"/1"; // "../storage/emulated/1" Doesn't work- does not write to external sdcard.
String finalPath = showPath+"/external_sd"; // "../storage/emulated/external_sd" Doesn't work either...
File appDir = new File(finalPath, "testFile");
appDir.mkdir();
}
I thought for sure that having my finalPath string = "/storage/emulated/1" or "/storage/emulated/external_sd" would have written a directory to the removeable sdcard, but neither did. Functionally, it seems as if /external_sd is read-only, however checking permissions I find that owner/group/users are all checked. Suggestions?
Second update 11/21/2015 8:10pm After a quick review of /proc/mounts I found the following storage/sdcard references,
/dev/fuse /storage/sdcard1 ...
/dev/fuse /storage/emulated/0 ...
/dev/fuse /storage/emulated/0/Android/obb ...
/dev/fuse /storage/emulated/legacy ...
/dev/fuse /storage/emulated/legacy/Android/obb ...
Based on this I revised,
File appDir = new File(Environment.getExternalStorageDirectory().getParent() + "/external_sd", "TestFile");
to,
File appDir = new File(/storage/sdcard1, "testFile");
and was able to finally create a directory on my removeable sdcard. This is clearly a dirty, kludgy fix. Suggestions on a better way? Full /proc/mount for the external sdcard are below. TIA
/dev/fuse /storage/sdcard1 fuse rw,nosuid,nodev,noexec,noatime,user_id=1023,group_id=1023,default_permissions,allow_other 0 0