android how do i crete folder and show on screen -
i'd create gallery folder in internal memory in screenshot below:
when click on album, want show list of images inside it.
string dirpath = getfilesdir().getabsolutepath() + file.separator + "newfoldername"; file projdir = new file(dirpath);
for creating folder app here code below takes string name of folder , checks if sd card available , if creates folder of name in pictures folder else if sd card not present creates folder same name in internal memory app installed data/data.com.myapp/files/yourfolder
public file createdirectoryforapp(context con, string dirname) { file directory=null; /* * sections checks phone see if there sd card. if * there sd card, directory created on sd card */ if (isexternalstoragewritable()) { // search directory on sd card directory = new file(environment.getexternalstoragepublicdirectory(environment.directory_pictures) + "/"+dirname+"/"); // if no directory exists, create new directory store test // results if (!directory.exists()) { directory.mkdir(); } } else { //create new file directory object in internal memory no sd card available directory = new file(con.getfilesdir() + "/"+dirname+"/"); // if no directory exists, create new directory if (!directory.exists()) { directory.mkdir(); } } return directory; } //method used above check external storage public static boolean isexternalstoragewritable() { string state = environment.getexternalstoragestate(); if (environment.media_mounted.equals(state)) { return true; } return false; }
and files specific extension , further files in inner directories(which files) can use following method
private list<file> getlistfiles(file parentdir) { arraylist<file> infiles = new arraylist<file>(); file[] files = parentdir.listfiles(); (file file : files) { if (file.isdirectory()) { infiles.addall(getlistfiles(file)); } else { if(file.getname().endswith(".png")){ infiles.add(file); } } } return infiles; }
and visually represent information depends on how design layout , display data after getting these files.
Comments
Post a Comment