阅读:4790回复:2
android判断U盘为fat32格式
用途:
U盘升级固件前检查U盘格式为Fat32 直接上code: private boolean isFat32Usb(Context context){ String PATH_USB = ""; StorageManager mStorageManager = (StorageManager) context.getSystemService(Context.STORAGE_SERVICE); Class<?> volumeInfoClazz; Class<?> diskInfoClaszz; try { volumeInfoClazz = Class.forName("android.os.storage.VolumeInfo"); diskInfoClaszz = Class.forName("android.os.storage.DiskInfo"); Method StorageManager_getVolumes=Class.forName("android.os.storage.StorageManager").getMethod("getVolumes"); Method VolumeInfo_GetDisk = volumeInfoClazz.getMethod("getDisk"); Method VolumeInfo_GetPath = volumeInfoClazz.getMethod("getPath"); Method DiskInfo_IsUsb = diskInfoClaszz.getMethod("isUsb"); Method DiskInfo_IsSd = diskInfoClaszz.getMethod("isSd"); List<Object> List_VolumeInfo = (List<Object>) StorageManager_getVolumes.invoke(mStorageManager); assert List_VolumeInfo != null; for(int i=0; i<List_VolumeInfo.size(); i++){ Object volumeInfo = List_VolumeInfo.get(i); Object diskInfo = VolumeInfo_GetDisk.invoke(volumeInfo); if(diskInfo==null)continue; boolean sdExists = (boolean) DiskInfo_IsSd.invoke(diskInfo); boolean usbExists = (boolean) DiskInfo_IsUsb.invoke(diskInfo); File file= (File) VolumeInfo_GetPath.invoke(volumeInfo); Field fsTypeField = volumeInfo.getClass().getField("fsType"); String fsType = (String) fsTypeField.get(volumeInfo); if(usbExists){//usb assert file != null; PATH_USB =file.getAbsolutePath(); return TextUtils.isEmpty(PATH_USB) && TextUtils.equals(fsType, "vfat"); } } } catch (Exception e) { e.printStackTrace(); } return false; } |
|
最新喜欢:zhaoyf... |
沙发#
发布于:2022-01-20 09:15
其实我一直不明白这些U盘格式有什么用,什么FAT FAT32 exFAT不是一样都是存储吗
|
|
|
板凳#
发布于:2022-01-20 09:51
|
|