Reputation: 652
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.
Upvotes: 3
Views: 1139
Reputation: 652
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.
Upvotes: 3