问题
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.
回答1:
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
回答2:
I've found a way around it by doing this.... Settings > Wireless & Network > USB utilities and click the button > then (and ONLY then) plug in USB cable
来源:https://stackoverflow.com/questions/10934099/android-and-jfilechooser