/// <summary> /// Uses the Linux Android.OS.StatFS wrapper call to try and see how many blocks are /// free/used/available. Results are returned in bytes. /// </summary> /// <param name="path">The path to use for the basis of the size check</param> /// <returns># of bytes free if successful, 0 if none</returns> public static FileSystemBlockInfo GetFileSystemBlockInfo(string path) { var statFs = new StatFs(path); var fsbi = new FileSystemBlockInfo(); if (Build.VERSION.SdkInt >= Android.OS.BuildVersionCodes.JellyBeanMr2) { fsbi.Path = path; fsbi.BlockSizeBytes = statFs.BlockSizeLong; fsbi.TotalSizeBytes = statFs.BlockCountLong * statFs.BlockSizeLong; fsbi.AvailableSizeBytes = statFs.AvailableBlocksLong * statFs.BlockSizeLong; fsbi.FreeSizeBytes = statFs.FreeBlocksLong * statFs.BlockSizeLong; } else // this was deprecated in API level 18 (Android 4.3), so if your device is below level 18, this is what will be used instead. { fsbi.Path = path; // disable warning about obsoletes, since earlier versions of Android are using the deprecated versions // ReSharper disable CSharpWarnings::CS0618 fsbi.BlockSizeBytes = (long)statFs.BlockSize; fsbi.TotalSizeBytes = (long)statFs.BlockCount * (long)statFs.BlockSize; fsbi.FreeSizeBytes = (long)statFs.FreeBlocks * (long)statFs.BlockSize; fsbi.AvailableSizeBytes = (long)statFs.AvailableBlocks * (long)statFs.BlockSize; // ReSharper restore CSharpWarnings::CS0618 } return(fsbi); }
private static FileSystemBlockInfo GetFileSystemBlockInfo() { if (!string.IsNullOrWhiteSpace(_path)) { _fileSystemBlockInfo = ExternalSdStorageHelper.GetFileSystemBlockInfo(_path); return(_fileSystemBlockInfo); } return(null); }