@SuppressLint("PrivateApi")
private String getStoragePath(Context context, boolean isUsb){
String path="";
StorageManager mStorageManager = (StorageManager) contextgetSystemService(ContextSTORAGE_SERVICE);
Class<> volumeInfoClazz;
Class<> diskInfoClaszz;
try {
volumeInfoClazz = ClassforName("androidosstorageVolumeInfo");
diskInfoClaszz = ClassforName("androidosstorageDiskInfo");
Method StorageManager_getVolumes=ClassforName("androidosstorageStorageManager")getMethod("getVolumes");
Method VolumeInfo_GetDisk = volumeInfoClazzgetMethod("getDisk");
Method VolumeInfo_GetPath = volumeInfoClazzgetMethod("getPath");
Method DiskInfo_IsUsb = diskInfoClaszzgetMethod("isUsb");
Method DiskInfo_IsSd = diskInfoClaszzgetMethod("isSd");
List<Object> List_VolumeInfo = (List<Object>) StorageManager_getVolumesinvoke(mStorageManager);
assert List_VolumeInfo != null;
for(int i=0; i<List_VolumeInfosize(); i++){
Object volumeInfo = List_VolumeInfoget(i);
Object diskInfo = VolumeInfo_GetDiskinvoke(volumeInfo);
if(diskInfo==null)continue;
boolean sd= (boolean) DiskInfo_IsSdinvoke(diskInfo);
boolean usb= (boolean) DiskInfo_IsUsbinvoke(diskInfo);
File file= (File) VolumeInfo_GetPathinvoke(volumeInfo);
if(isUsb == usb){//usb
assert file != null;
path=filegetAbsolutePath();
}else if(!isUsb == sd){//sd
assert file != null;
path=filegetAbsolutePath();
}
}
} catch (Exception e) {
YYLogprint(TAG, "[——————— ——————— Exception:"+egetMessage()+"]");
eprintStackTrace();
}
return path;
}
以上就是关于Android开发中,获取U盘或SD卡路径。全部的内容,包括:Android开发中,获取U盘或SD卡路径。、、等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)