Reputation: 614
I've got a weird problem over here with an app I am developing. It's using Apache Codova 3.0.0 and the stock file plugin to create a directory on external storage of a Samsung Galaxy Nexus with Android 4.3 and to add some files into there.
What happens here is that I am actually able to do this but the created directory including the files are not showing up when I connect the device to a computer as a mass storage device. All other folders are displaying normally but the one I created. When I browse the device with 'adb shell' I can see the folder, though, and its directory mode from 'ls -al' is exactly the same as that of all the others. READ and WRITE permissions are granted to the app.
I've also tried the same in Android code and it behaves exactly the same:
File f = new File(Environment.getExternalStorageDirectory().toString()+"/myFolder");
if (!f.isDirectory()) {
f.mkdir();
Log.i("myApp", "Created directory: "+f);
}
This operation succeeds but the folder is again not visible when I reconnect the device to a computer. To mention it: I run the application from the IDE - so maybe: is there a sandbox or such that I am not aware of, that could result in showing stuff in /sdcard using adb shell but not when connected as external storage?
I guess I must miss something elementary here and hope that you guys have an answer for me :)
Thanks!
Upvotes: 2
Views: 2776
Reputation: 11
Be sure not to call MediaScannerConnection.scanFile
on directory, only on files. In that case my Lg (Android 4.4.2) make directory shown in MTP as regular file!
Upvotes: 1
Reputation: 82563
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.
Upvotes: 4