android - Why can i not make a directory inside Environment.DIRECTORY_PICTURES? -
this code
file selfielocation = new file(getexternalfilesdir(environment.directory_pictures), "daily selfies"); boolean isdirectory = false; if(!selfielocation.isdirectory()) { //creates directory named file selfielocation.mkdir(); isdirectory = selfielocation.isdirectory(); } //array of strings for(string selfiepath: selfielocation.list()) { selfies.add(selfiepath); }
basically trying create own customizable directory inside of standard directory in place pictures available user.
i looked @ related threads , saw one, android: unable create directory in default pictures folder. made sure had call getexternal...., , not have environment.directory_pictures parameter. looked on here http://developer.android.com/guide/topics/data/data-storage.html#filesexternal , saw had right method call/format create customizable folder in external memory. docs example
file file = new file(environment.getexternalstoragepublicdirectory( environment.directory_pictures), albumname); if (!file.mkdirs()) { log.e(log_tag, "directory not created"); }
i stepped through code , saw local variable isdirectory stayed @ false after call selfielocation.mkdir(). know why directory cannot created?
try create directory file#mkdirs()
, not file#mkdir()
. latter assumes parent directories in place, won't create directory if of parents don't exist.
also, take @ permissions in androidmanifest.xml
. need following permissions in order read/write content on external storage:
<manifest ...> <uses-permission android:name="android.permission.write_external_storage" /> <uses-permission android:name="android.permission.read_external_storage" /> ... </manifest>
android.permission.read_external_storage
isn't required now, it be in future releases of android.
Comments
Post a Comment