Unable to create file on removeable sdcard in Android 5.0.1 -


i working on application needs ability create files on removeable sdcard in samsung s4 i9295 device. running stock samsung rom 5.0.1 has been rooted. test purposes, have been trying create these files hardcoding paths specific device, have been unable create files on removeable card. code below creates files expected on internal sdcard not on removeable card.

//creates directory on internal sdcard public void createinternalsdcardfile(){          log.v(logtag, "create internal sdcard file initiated");     string szfilepath = "/storage/sdcard0";     file appdir = new file(szfilepath, "targetfile");     appdir.mkdir();       maketimestamp();     file exportdir = new file(szfilepath, "targetfile/" + szdatetime);     exportdir.mkdir(); }  //creates directory @ root of removeable sdcard public void createremoveablesdcardfile(){        log.v(logtag, "create removeable sdcard file initiated");     string szfilepath = "/storage/extsdcard";     file appdir = new file(szfilepath, "targetfile");     appdir.mkdir();       maketimestamp();     file exportdir = new file(szfilepath, "targetfile/" + szdatetime);     exportdir.mkdir(); } public void maketimestamp(){         date t = new date();             simpledateformat sdf = new simpledateformat("yyyymmddhhmmss");     szdatetime = sdf.format(t);  } 

a review of logcat shows nothing suspicious. relevant manifest permissions are:

<uses-permission android:name="android.permission.read_external_storage" /> <uses-permission android:name="android.permission.write_external_storage"></uses-permission> <uses-permission android:name="android.permission.read_secondary_storage" /> <uses-permission android:name="android.permission.write_secondary_storage"></uses-permission> <uses-permission android:name="android.permission.storage" /> 

file permissions "/storage/extsdcard" on device owner has read, write, execute. group has read, write, , execute well. others execute. file permissions "/storage/sdcard0" read, write, execute everybody.

why not able write on removeable card device? specific suggestions solution appreciated.

note: working getexternalfilesdirs() , able write internal sdcard not removeable card case static references. static paths used in example code here simplification.

got it. in general, replacing...

string szfilepath = "/mnt/extsdcard/temp"; 

with this:

file[] fo = getexternalfilesdirs(null);     file f =fo[1]; 

has resolved issue. specific changes final test case are:

public void createremoveablesdcardfile(view view) {     file[] fo = getexternalfilesdirs(null);     file f =fo[1];     file appdir = new file(f, "targetfile");     appdir.mkdir();       maketimestamp();     file exportdir = new file(f, "targetfile/" + szdatetime);     exportdir.mkdir();          } 

this creates file on removeable sdcard here:

../extsdcard/android/data/net.google.example/file/ 

Comments

Popular posts from this blog

html - Styling progress bar with inline style -

java - Oracle Sql developer error: could not install some modules -

How to use autoclose brackets in Jupyter notebook? -