0

Is there a way to detect all SD Card drives connected to a Desktop computer? In Windows, SD Cards are visually distinct from other devices like built-in hard drives or similar. Is there a way to tell if a drive is an SD Card drive or not?

A Java way of listing all available filesystem roots for example is using the listRoots() method but it cannot tell the filesystem types such as external, internal, OS drive or whatever.

Is this even possible in pure Java?

Note:
I'm not asking to detect the Android phone SD Card since these are the results when searching for my question.

BullyWiiPlaza
  • 17,329
  • 10
  • 113
  • 185

1 Answers1

1

This answer solved it.

Example code:

USBDeviceDetectorManager manager = new USBDeviceDetectorManager();
List<USBStorageDevice> usbStorageDevices = manager.getRemovableDevices();

for(USBStorageDevice usbStorageDevice : usbStorageDevices)
{
    System.out.println(usbStorageDevice.getSystemDisplayName());
    System.out.println(usbStorageDevice.getDeviceName());
    System.out.println(usbStorageDevice.getRootDirectory());
}

I have my SD card, NAS, C: and D: drives connected. The following is printed:

SANDISK (E:)
SANDISK
E:\

As expected, only one result is returned because the SD card is treated as USB due to the USB reader being plugged into my laptop.

Community
  • 1
  • 1
BullyWiiPlaza
  • 17,329
  • 10
  • 113
  • 185
  • 1
    That… doesn't actually work? There isn't anything in your code which would distinguish a USB SD card from any other kind of USB storage device. And it won't pick up SD drives which aren't attached over USB (yes, they exist). –  Apr 12 '17 at 00:29
  • Okay but it's close enough for my purposes and most SD cards are attached via USB SD card readers these days anyway – BullyWiiPlaza Apr 13 '17 at 22:14
  • 1
    But not all USB storage devices are SD card readers. Your code will misidentify anything else that happens to be hooked up via USB, like a flash drive or external hard disk. –  Apr 13 '17 at 22:21
  • Yeah, you're right. I should find a better solution then – BullyWiiPlaza Apr 13 '17 at 22:24