理解inode
896
2022-05-28
區分外置U盤及TF卡
最近有個項目有內置SD卡同時又保留了USB及sd卡口,由于要計算外置存儲設備的空間,嘗試了幾個方法均不理想最終使用如下方法 可以成功的區分外置設備是U盤還是SD卡。
主要通過如下方法區分U盤及TF卡
@SuppressLint("PrivateApi") ????private?String?getStoragePath(Context?context,?boolean?isUsb){ ????????String?path=""; ????????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