how to list all pdf files in my android device -
i found code how images.
can tell me how can .pdf files in internal storage , external storage?
final string[] columns = { mediastore.images.media.data, mediastore.images.media._id }; final string orderby = mediastore.images.media._id; //stores images gallery in cursor cursor cursor = getcontentresolver().query( mediastore.images.media.external_content_uri, columns, null, null, orderby); //total number of images int count = cursor.getcount(); //create array store path images string[] arrpath = new string[count]; (int = 0; < count; i++) { cursor.movetoposition(i); int datacolumnindex = cursor.getcolumnindex(mediastore.images.media.data); //store path of image arrpath[i]= cursor.getstring(datacolumnindex); log.i("path", arrpath[i]); }
possible solution can go every folder , check if .pdf exists or not if yes can whaterver want file
public void search_dir(file dir) { string pdfpattern = ".pdf"; file filelist[] = dir.listfiles(); if (filelist != null) { (int = 0; < filelist.length; i++) { if (filelist[i].isdirectory()) { search_dir(filelist[i]); } else { if (filelist[i].getname().endswith(pdfpattern)){ //here have file. } } } } }
and function call be
search_dir(environment.getexternalstoragedirectory());
Comments
Post a Comment