UsbManager usbManager = (UsbManager) getSystemService(Context.USB_SERVICE);
HashMap<String, UsbDevice> deviceList = usbManager.getDeviceList();
Iterator<UsbDevice> deviceIterator = deviceList.values().iterator();
List<UsbDevice> usbDevices = new ArrayList<>();
while (deviceIterator.hasNext()) {
UsbDevice device = deviceIterator.next();
usbDevices.add(device);
if(device.getProductName().toLowerCase().contains("toofifi")){
return null;
}
}
List<String> usbs = new ArrayList<>();
StorageManager storageManager = (StorageManager) this.getApplicationContext().getSystemService(Context.STORAGE_SERVICE);
StorageVolume[] volumes = storageManager.getVolumeList();
if (volumes == null || volumes.length == 0) {
return usbs;
}
String path;
for (StorageVolume item : volumes) {
path = item.getPath();
String state = storageManager.getVolumeState(path);
String name = item.getDescription(getApplicationContext());
if (state == null || !state.equals(Environment.MEDIA_MOUNTED)) {
continue;
} else {
if(name.toLowerCase().contains("toofifi")){
continue;
}
if (!("/storage/emulated/0").equals(path)) {
usbs.add(path);
}
}
}
return usbs;