With Android 6.0 and Above, not able to compile the below code.
It is not able to import android.os.storage.VolumeInfo
Needs to get volumeInfos from getVolumes() API.
Below is the code.
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
StorageManager sm = ctx.getSystemService(StorageManager.class);
List<VolumeInfo> volumeInfos = sm.getVolumes();
for (VolumeInfo vol : volumeInfos) {
if(vol.type==VolumeInfo.TYPE_PUBLIC
&& (vol.state==VolumeInfo.STATE_MOUNTED || vol.state==VolumeInfo.STATE_MOUNTED_READ_ONLY)){
String desc = sm.getBestVolumeDescription(vol);
boolean isSdCard = desc.toLowerCase().contains("sd");
list.add(new StorageInfo(vol.path, true, isSdCard, vol.fsUuid, vol.fsLabel, desc, isSdCard?0:usbCounter++));
}
}
return list;
}