0

i created folders on external storage. in device these folders are created properly and i can see and use them. now i want to see these created folders on my PC if i connect it to USB.but i was not able to see any of the created folders. after that i used MediaScannerConnection class for media scan for given folder path . after that i am able to see the created folder but the innermost folder on a particular path is not visible properly. for example suppose i created 3 folder(pragmatically) and for example i want to create folder abc/def/h so on external storage of my phone than path in file explorer of eclipse is mnt/shell/emulated/0/abc/def/h and in our phone we can see it in file Manager internal storage/abc/def/h. but the problem is after using MEdia Scanner i cab see folder in PC but the innermost folder "h" which i created is not resemble like a folder , it becomes a file of 4kb not a folder. so like this if create lots of folder the inner most folder is not a type of file folder, but a type of file only.. although if i dont use mediascanner and do power off and power on my phone than it works properly means after power on / off i can see all the created folder properly . but i want to see the created folders just after creation.my code is as follows

public void ReadFileAndMakeFolders(Context context){
    File file3;
    File file2;

     String[] splitedString;

     try {  

         //Attaching BufferedReader to the FileInputStream by the help of InputStreamReader  
         FileInputStream fis = context.openFileInput("databaseee.txt");

           InputStreamReader isr = new InputStreamReader(fis,"UTF-8");

           BufferedReader bufferedReader = new BufferedReader(isr);

           int i=0;
         String inputString;  
         //Reading data line by line and storing it into the stringbuffer                
         while ((inputString = bufferedReader.readLine()) != null) {  
             i++;

             splitedString = inputString.trim().split("\\s+");
             Toast.makeText(this, splitedString.length+""+ splitedString[1], Toast.LENGTH_SHORT).show();




              file2 = new File(splitedString[1]);
             file3 = file2.getParentFile();
            Log.i("mistake",file3.toString());


             String state = Environment.getExternalStorageState();

             if (Environment.MEDIA_MOUNTED.equals(state)) {
                 Toast.makeText(this, state, Toast.LENGTH_SHORT).show();

             }
                 File path = Environment.getExternalStorageDirectory();

                    File file = new File(path, file3.toString());




                 if (file.mkdirs()) {
                     Toast.makeText(this, "created" , Toast.LENGTH_SHORT).show();


                 }


                MediaScannerConnection.scanFile(this, new String[] { file.toString() }, null,
                            new MediaScannerConnection.OnScanCompletedListener() {
                                public void onScanCompleted(String path, Uri uri) {
                                    Log.i("ExternalStorage", "Scanned " + path + ":");
                                    Log.i("ExternalStorage", "-> uri=" + uri);
                                }
                    });









         }  
         fis.close();
         bufferedReader.close();
         isr.close();




     } catch (IOException e) {  
         e.printStackTrace();  
     }  
     //Displaying data on the toast  




 }  
shaktisinghmoyal
  • 312
  • 1
  • 5
  • 14
  • `how to create folder in mnt/shell/emulated/0`. That path does not exist. Name one device please which has that. You cannot add folders to a non existing path. – greenapps Sep 17 '14 at 11:43
  • in file manager/internal storage there are lots of folders . i want to create folders here near by media,movies,music folder.if you go through the file explorer if device than u can find these folders under mnt/shell/emulated/0/ sorry i can not tell the names of devices due to some security reasons – shaktisinghmoyal Sep 17 '14 at 15:43
  • I just told you that /mnt/shell does not exist so how can you ask me to look there? – greenapps Sep 17 '14 at 19:13
  • i have phone with user debug binary and in file explorer this mnt/shell/emulated/0 path existes. al the music,movies,ringtones are available on this path only – shaktisinghmoyal Sep 18 '14 at 04:32
  • Ok. Do you still need help to create more folders? – greenapps Sep 18 '14 at 06:03
  • yes i wanted to create more folders and i created by using Environment.getExternalStorageDirectory(); but now the problem is i can see these folders in my phone's file manager but when i connect it to my pc by using USB than it is not showing those folders in my PC. – shaktisinghmoyal Sep 19 '14 at 14:12

1 Answers1

0

You need to update MediaScanner using MediaScannerConnection.scanFile. Check my answer for a similar question at https://stackoverflow.com/a/31497971/4419474

Community
  • 1
  • 1
Chebyr
  • 2,171
  • 1
  • 20
  • 30