java - App won't create a new directory -
i'm making audio recorder app. app supposed record files , save them in external storage directory. how trying it:
declaring few global variables:
string externalstoragepath = environment.getexternalstoragedirectory().getabsolutepath(); string outputpath = externalstoragepath + "/android/data/com.whizzappseasyvoicenotepad/no_name.mp3"; //output path mp3 files file appdirectory = new file(externalstoragepath + "/android/data/com.whizzappseasyvoicenotepad"); //this directory want create when app started first time
few logs in oncreate check if externalstorage alright , working should be:
log.i("tag", "external storage directory: " + externalstoragepath); log.i("tag", "external storage state: " + environment.getexternalstoragestate());
log says external storage fine (storage/emulated/0) , state mounted.
then try create directory if doesn't exist yet:
if (!appdirectory.exists()) { try { appdirectory.createnewfile(); } catch (ioexception e) { // todo auto-generated catch block e.printstacktrace(); } }
i know external storage isn't working should if device connected pc usb cable, remove device usb , run app, folder isn't created should be. nothing happens basically.
you need use mkdir() instead of createnewfile() :
appdirectory.mkdir();
also need set permission in androidmanifest.xml :
android.permission.write_external_storage
Comments
Post a Comment