java - How can I access internal storage to list all pdf files in ListView -
public arraylist<string> getfiles(string directorypath) { arraylist<string> myfiles = new arraylist<string>(); file f = new file(directorypath); f.mkdirs(); file[] files = f.listfiles(); if (files.length == 0) return null; else { (int i=0; i<files.length; i++) myfiles.add(files[i].getname()); } return myfiles; }
and called function passing enviroment.getexternalstoragedirectory()
now how can same internal storage?
public arraylist<string> searchpdfinexternalstorage(file folder) { arraylist<string> myfiles = new arraylist<string>(); if (folder != null) { if (folder.listfiles() != null) { (file file : folder.listfiles()) { if (file.isfile()) { //.pdf files if (file.getname().contains(".pdf")) { myfiles.add(file.getpath()); log.d("filepath-------", "" + file.getpath()); } } else { searchpdfinexternalstorage(file); } } } } }
get list of pdf file sd-card.you can load list on listview
searchpdfinexternalstorage(environment.getexternalstoragedirectory());
Comments
Post a Comment