StorageManager mStorageManager;
mStorageManager = (StorageManager) getSystemService(Context.STORAGE_SERVICE);
//获取所有挂载的设备(内部sd卡、外部sd卡、挂载的U盘)
List<StorageVolume> volumes = mStorageManager.getStorageVolumes();
try {
Class<?> storageVolumeClazz = Class
.forName("android.os.storage.StorageVolume");
//通过反射调用系统hide的方法
Method getPath = storageVolumeClazz.getMethod("getPath");
Method isRemovable = storageVolumeClazz.getMethod("isRemovable");
for (int i = 0; i < volumes.size(); i++) {
StorageVolume storageVolume = volumes.get(i);//获取每个挂载的StorageVolume
//通过反射调用getPath、isRemovable
String storagePath = (String) getPath.invoke(storageVolume); //获取路径
boolean isRemovableResult = (boolean) isRemovable.invoke(storageVolume);//是否可移除
String description = storageVolume.getDescription(this);
LogUtil.e("Legejason i=" + i + " ,storagePath=" + storagePath
+ " ,isRemovableResult=" + isRemovableResult +" ,description="+description);
}
} catch (Exception e) {
LogUtil.e("Legejason e:" + e);
}
Android 获取外部挂在的设备路径包括内部SD卡,外部SD卡,U盘的设备路径
最新推荐文章于 2025-03-23 13:56:09 发布