Android UsbManager:获取USB驱动器名称

3

我需要U盘的驱动器名称,就像下面图片中突出显示的那样:

enter image description here

我尝试使用UsbDevice.getDeviceName()UsbDevice.getProductName()UsbDevice.getManufacturerName(),但它们都没有给出驱动器名称。

1个回答

3
最终,我找到了解决方案。使用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 返回驱动器名称。

最初的回答

使用volume.getUuid()同样可以获取UUID,非常完美。 - Kizito Ikapel

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接