Folder Added on Android Is Not Visible via Usb

Folder added on Android is not visible via USB

None of the above helped me, but this worked:
The trick being to NOT scan the new folder, but rather create a file in the new folder and then scan the file. Now Windows Explorer sees the new folder as a true folder.

    private static void fixUsbVisibleFolder(Context context, File folder) {
if (!folder.exists()) {
folder.mkdir();
try {
File file = new File(folder, "service.tmp");//workaround for folder to be visible via USB
file.createNewFile();
MediaScannerConnection.scanFile(context,
new String[]{file.toString()},
null, (path, uri) -> {
file.delete();
MediaScannerConnection.scanFile(context,
new String[]{file.toString()} ,
null, null);
});
} catch (IOException e) {
e.printStackTrace();
}
}
}

Thanks to https://issuetracker.google.com/issues/37071807#comment90

You also should scan every created file in the directory analogically:

   private static void fixUsbVisibleFile(Context context, File file) {
MediaScannerConnection.scanFile(context,
new String[]{file.toString()},
null, null);
}

Folder and files added in android not visible via USB

I have managed to get it working. The trick here is to scan every new file created in the that directory. Every time I create a new file I follow it with below line of code.

MediaScannerConnection.ScanFile(Android.App.Application.Context, new String[] { path }, null, null);

Created android directory but not visible via PC usb connection

I figured out a solution the problem for anyone encountering the same thing.

  • unplug phone from computer
  • go to --- settings > apps > app info
  • use the options to show system apps
  • settings > apps > app info (system apps) > external storage > app data > storage
  • then press clear data
  • go to --- settings > apps > app info
  • use the options to show system apps
  • settings > apps > app info (system apps) > media storage > app data > storage
  • then press clear data
  • restart the phone
  • plug the phone back into the pc
  • set the phone to transfer files (mtp)
  • updated/new folders should be visible

I'm not sure why the phone requires you to do this or if there's a way to refresh this programatically when the files are created but if I discover any further information I'll post it in a comment below this answer.

Folder and files added in android not visible via USB

I have managed to get it working. The trick here is to scan every new file created in the that directory. Every time I create a new file I follow it with below line of code.

MediaScannerConnection.ScanFile(Android.App.Application.Context, new String[] { path }, null, null);

Folder created on Android external storage isn't visible via MTP but showing in adb shell

New files and folders may take some time to show up via MTP. If you can see your folder through adb, then your code is running fine.

MTP indexing is done every now and then by Android (I'm not sure of the exact time delay), and hence new files don't show up as soon as they are created. You can try force running the MediaScanner by code to force an index, or restarting your device.

Created folder is not visible in the file explorer..

Damn! :)

Now I solved my problem...I was misunderstanding the operation of creating files in the file system.

When I spoke of file explorer I meant the file explorer of the operating system and NOT the file explorer in the DDMS :).

I thought when I create a file I will see it in the file explorer of the operating system but when the device is connected to the PC the files can only be seen in the DDMS file explorer.

Sorry I'm new to Android ;)

When the App is running standalone without PC connection and afterwards I connect with the PC I see the created files and folders of course :)

Thanks for help



Related Topics



Leave a reply



Submit