directory - android Reading all the Directories in SDCARD which has images -


i trying read images in sdcard directory in present. e.g: if there file test.jpg in /mnt/sdcard/album1 , test2.jpg in /mnt/sdcard/album1/album2 should able directory name album1 , album2. have written code in recursive manner, works when no of folders less when number of directories increases loop come out of it.

      public void getimagefoldes(string filepath){               string albumpath;             file file = new file(filepath);      file[] files = file.listfiles();     (int fileinlist = 0; fileinlist < files.length; fileinlist++)       {         file filename;         filename =files[fileinlist];          if(filename.ishidden()|| filename.tostring().startswith("."))             return;          if (filename.isdirectory()){              albumpath = filename.tostring();             string[] split;             string title;             split= albumpath.split("/");             title=split[split.length-1];             result = new thumbnailresults();             result.settitle(title);             result.setpath(albumpath);             result.setislocal(true);             //result.setcreated("05-06-2011");             getimagefoldes(filename.tostring());         }         else{             if (files.length !=0)             {                 //if file image file store album name                  if ((files[fileinlist].tostring()).contains(".png")||                         (files[fileinlist].tostring()).contains(".jpg")||                         (files[fileinlist].tostring()).contains(".jpeg")){                     if (!results.contains(result)){                         result.seturi(uri.parse(files[fileinlist].getpath()));                         results.add(result);                         myadapter.notifydatasetchanged();                      }                 }                    }         }     } } 

use following code. path of images , directories sdcard.

public static arraylist<string> getpathofallimages(activity activity) {         arraylist<string> absolutepathofimagelist = new arraylist<string>();         string absolutepathofimage = null;         string nameoffile = null;         string absolutepathoffilewithoutfilename = null;         uri uri;         cursor cursor;         int column_index;         int column_displayname;         int lastindex;         // absolutepathofimages.clear();               uri = android.provider.mediastore.images.media.external_content_uri;              string[] projection = { mediacolumns.data,                     mediacolumns.display_name };              cursor = activity.managedquery(uri, projection, null, null, null);             column_index = cursor.getcolumnindexorthrow(mediacolumns.data);              column_displayname = cursor                     .getcolumnindexorthrow(mediacolumns.display_name);              // cursor.movetofirst();             while (cursor.movetonext()) {                 // for(int i=0; i<cursor.getcolumncount();i++){                 // log.i(tag,cursor.getcolumnname(i)+".....data present ...."+cursor.getstring(i));                 // }                 // log.i(tag,"=====================================");                  absolutepathofimage = cursor.getstring(column_index);                 nameoffile = cursor.getstring(column_displayname);                  lastindex = absolutepathofimage.lastindexof(nameoffile);                  lastindex = lastindex >= 0 ? lastindex                         : nameoffile.length() - 1;                  absolutepathoffilewithoutfilename = absolutepathofimage                         .substring(0, lastindex);                       if (absolutepathofimage != null) {                         absolutepathofimagelist.add(absolutepathofimage);                     }              }           // log.i(tag,"........detected images grid....."         // + absolutepathofimagelist);         return absolutepathofimagelist;     } 

Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -