Android UsbManager:检索 USB 驱动器名称
Android UsbManager: Retrieve USB drive name
我需要下图中突出显示的 Pendrive 驱动器名称:
我尝试了 UsbDevice.getDeviceName()
、UsbDevice.getProductName()
和 UsbDevice.getManufacturerName()
,但其中 none 给出了驱动器名称。
终于,我找到了解决办法。使用 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
具有驱动器名称。
我需要下图中突出显示的 Pendrive 驱动器名称:
我尝试了 UsbDevice.getDeviceName()
、UsbDevice.getProductName()
和 UsbDevice.getManufacturerName()
,但其中 none 给出了驱动器名称。
终于,我找到了解决办法。使用 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
具有驱动器名称。