I need the drive name of Pendrive like highlighted in the below image:

I tried UsbDevice.getDeviceName(), UsbDevice.getProductName() & UsbDevice.getManufacturerName() but none of them giving the drive name.
Finally, I found the solution. use StorageManager.
StorageManager storage = (StorageManager) getSystemService(STORAGE_SERVICE);
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N) {
List<StorageVolume> volumes = storage.getStorageVolumes();
for (StorageVolume volume :volumes) {
Log.d("STORAGE", "Device name:" + volume.getDescription(this));
}
}
StorageVolume.getDescription is having the drive name.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With