// determine if the SD card exists boolean sdcardexist = environment.getexternalstoragestate (). Equals ( Android.os.Environment.MEDIA _mounted); // get the SD card root directory if (sdcardexist) { = environment.getexternalstoragedirectory (); = Dir.getabsolutepath () + "/Macheng Homestead Information/"; ArrayList<String> folder = getFolder (path); = listparent (folder); }
------------------------
//list conversion to string[] PublicString[] Listparent (arraylist<string>list) { intSize =list.size (); String[] Array=NewString[size]; for(inti = 0; I < list.size (); i++) {Array[i]=(String) list.get (i); } returnArray; } //Check if a folder exists Booleanisfolderexists (String strfolder) {File file=NewFile (strfolder); returnfile.exists (); } //Scan folder name under folder directory PublicArraylist<string>GetFolder (String path) {ArrayList<String> names =NewArraylist<string>(); File File=NewFile (path); if(File.isdirectory ()) {file[] array=File.listfiles (); for(inti = 0; i < Array.Length; i++) {File F=Array[i]; Names.add (F.getname ()); System.out.println ("Folder name" +f.getname ()); } } returnnames; } //scan the data inside the folder PublicArraylist<string>Folderscan (String path) {File file=NewFile (path); ArrayList<String> names =NewArraylist<string>(); if(File.isdirectory ()) {file[] array=File.listfiles (); for(inti = 0; i < Array.Length; i++) {File F=Array[i]; if(F.isfile ()) {//FILE TYPEString name =F.getname (); if(Name.contains (". jpg") {names.add (name); FileScan (F.getabsolutepath ()); } } Else{//FOLDER TYPEFolderscan (F.getabsolutepath ()); } } } returnnames; } //Scan Public voidfilescan (String file) {Uri data= Uri.parse ("file://" +file); Sendbroadcast (NewIntent (intent.action_media_scanner_scan_file, data)); }
Android Operation SD Card