Search code examples
javaandroidandroid-4.0-ice-cream-sandwichjfilechooserandroid-2.3-gingerbread

Android and JFileChooser


I've developed a desktop application that allows the user to extract images from their phone.

When I first started this project, my android was running Gingerbread. When I plugged my phone into the laptop via USB, it would appear as a "Device with removable storage". Therefore, the JFileChooser would pick it up.

nwdir = new JFileChooser();
            nwdir.setCurrentDirectory(new java.io.File("C:\\"));
            nwdir.setDialogTitle(choosertitle);
            nwdir.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
            nwdir.setAcceptAllFileFilterUsed(true);

However, I recently upgraded the phone's o/s to Icecream and it now shows up on the desktop as a "portable device". This is something that the JFileChooser cannot see?!

Has anyone got any suggestions on how to get around this problem? I was going to roll back the O/S of the phone, but this somewhat limits the application's device support.


Solution

  • The default transfer mode has been changed in Android 4.0 Ice Cream Sandwich from USB Mass Storage mode to MTP (Media Transfer Protocol) which doesn't use a standard filesystem mount. On some phones it is possible to change the USB mode while on others it may be necessary to install an apk to enable it