From research I have found that it is possible to determine the available space for storing app files on iOS, Android and UWP using dependency services with the Platform specific code below:
For iOS:
private double GetRemainingStorageSpace(string directoryPath)
{
var freeExternalStorage = NSFileManager.DefaultManager.GetFileSystemAttributes(directoryPath).FreeSize;
return (double)freeExternalStorage;
}
For Android it can be done like:
var path = new StatFs(directoryPath);
long blockSize = path.BlockSizeLong;
long avaliableBlocks = path.AvailableBlocksLong;
double freeSpace = blockSize * avaliableBlocks;
return freeSpace
or like this:
var fl = new Java.IO.File(directoryPath);
var freeSpace = fl.UsableSpace;
return (double)freeSpace;
For UWP:
string freeSpaceKey = "System.FreeSpace";
StorageFolder folder = await StorageFolder.GetFolderFromPathAsync(directoryPath);
var properties = await folder.Properties.RetrievePropertiesAsync(new string[]
{
freeSpaceKey
});
var freeSpace = properties[freeSpaceKey];
return (UInt64)freeSpace;
My question then is:
1.) Do these lines of code above actually return the amount of bytes that can be stored in a specific directory? Or do they return the amount of bytes that can be stored on the whole device?
2.) For Android I am not too sure what the difference between the two ways of doing this are I am hoping for an explanation of the difference between the both of then and which is a better to use?
Would appreciate an explanation.