Android 11 getMethod("getPath");方法被移除了。
但是提供了getDirectory,使用storageVolume.getDirectory().getAbsolutePath()来获取存储路径。
获取存储路径方法代码如下:
Class<?> storageVolumeClazz = Class.forName("android.os.storage.StorageVolume");
//by lxy modify
Method getPath = null;
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.R) {
getPath = storageVolumeClazz.getMethod("getPath");
}
List<StorageVolume> volumes = mStorageManager.getStorageVolumes();
for (int i = 0; i < volumes.size(); i++) {
StorageVolume storageVolume = volumes.get(i);//获取每个挂载的StorageVolume
String storagePath = "";
//通过反射调用getPath、isRemovable
// String storagePath = (String) getPath.invoke(storageVolume)