1

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);
  • The Storage Access Framework itself will not have anything directly for this, as it is not tied to a filesystem. After all, what is the total or available size of Google Drive? – CommonsWare Jul 23 '19 at 20:44
  • Yes, I understand, but the app targeted Api 28 works differently on Device with api 29 and the only way to access the SD card is now via Storage Access Framework – Michal Bukáček Jul 23 '19 at 21:38
  • My point is that I suspect that you will need to remove your app features that relied upon getting these size values. – CommonsWare Jul 23 '19 at 21:39
  • Yes, these old features that I relied on will be used for older devices, but I don't know what new features to use or how to do to determine the size of the SD card on Android Q. Here is the same query similar problem. https://stackoverflow.com/questions/56663624/how-to-get-free-and-total-size-of-each-storagevolume – Michal Bukáček Jul 24 '19 at 10:27

0 Answers0