I am trying to update my application (file manager) for proper functioning on Android Q. I understand that the only way to access the SD card will be through Storage Access Framework (https://developer.android.com/guide/topics/providers/document-provider) But I don't know how to find out the size of selected root direcory of SD card on Android Q.
I know a lot of ways to determine size from an absolute path, but the Storage Access Framework only returns a Uri and using it doesn't work
Another option is via StorageManager and via storageStatsManager.getTotalBytes unfortunately I cannot create a UUID uuid from storageVolume.getUuid() I think it not works on Android Q, when it comes to removable storage.
Do you know how to determine the size of storage on Android Q ? Or, if there is any new Permission for usage of Storage Manager with removable storage ?
My old methods don't work
StatFs stat = new StatFs(storage_path); // But I have only Uri.. :-(
long blockSize = stat.getBlockSizeLong();
long totalBlocks = stat.getBlockCountLong();
long availableBlocks = stat.getAvailableBlocksLong();
TotalMemorySize = totalBlocks * blockSize;
AvailableMemorySize = availableBlocks * blockSize;
or via
StorageManager storageManager = (StorageManager) context.getSystemService(Context.STORAGE_SERVICE);
...
...
String uuidStr = storageVolume.getUuid();
UUID uuid = uuidStr == null ? StorageManager.UUID_DEFAULT : UUID.fromString(uuidStr);
TotalMemorySize = storageStatsManager.getTotalBytes(uuid);
AvailableMemorySize = storageStatsManager.getFreeBytes(uuid);