Sanif SS
Sanif SS

Reputation: 652

Android UsbManager: Retrieve USB drive name

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

enter image description here

I tried UsbDevice.getDeviceName(), UsbDevice.getProductName() & UsbDevice.getManufacturerName() but none of them giving the drive name.

Upvotes: 3

Views: 1139

Answers (1)

Sanif SS
Sanif SS

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

Related Questions