Android - Accessing storage locations -


ok, quick heads new android programming. have basic experience java uni. i've been messing around android studio , app building samsung galaxy tab. sorry if has been asked before couldn't see it.

i have tried make app displays names of files on sd card. @ top level. made quick interface button , text view start (i'm away single text view wont display list had problems got anyway)

ended following code.

*public void showfolder(view view){     textview test = (textview)findviewbyid(r.id.view);     root = new file(environment.getrootdirectory().tostring());      file[] files;     files = root.listfiles();      string[] file_list;     file_list = root.list();* 

i ran using debugger see ended in both array lists. ran code 3 times on varied "environment.getrootdirectory" "getexternalstoragedirectory()" , "getdatadirectory()".

only getrootdirectory version return anything.in both other instances debugger shows null both files , files_list. know valid locations because used commands outputted strings can manually find on tablet file browser.

so, put, why dont 3 of these options return file lists? first thought permissions unsure how confirm this.

(sorry long post)

don't use tostring() create file. getrootdirectory() returns file object.

try this:

file root = environment.getrootdirectory(); string[] rootlist = root.list(); file[] rootlistfiles = root.listfiles(); 

also need obtain read_external_storage permission can see here in docs of getexternalstoragedirectory()


Comments

Popular posts from this blog

java - Jasper subreport showing only one entry from the JSON data source when embedded in the Title band -

serialization - Convert Any type in scala to Array[Byte] and back -

SonarQube Plugin for Jenkins does not find SonarQube Scanner executable -