如何知道android / ios上的可用磁盘空间? [英] How to know the available disk space on android/ios?

查看:100
本文介绍了如何知道android / ios上的可用磁盘空间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在将文件保存到缓存目录之前,我想知道设备上有多少可用空间(尤其是缓存目录所在的可用空间)。如何在android和ios上执行此操作?

before to save a file to the cache directory i want to know how much space are available on the device (especially the space available where the cache directory is located). How to do this on android and ios ? i m on delphi berlin.

推荐答案

好,这是所有平台的解决方案(取自 https://github.com/Zeus64/alcinoe ):

ok, here is the solution for all plateform (taken from https://github.com/Zeus64/alcinoe) :

  {$IFDEF ANDROID}
  aStatFS := TJStatFs.JavaClass.init(StringToJstring(aDir));
  if (TJBuild_VERSION.JavaClass.SDK_INT < 18 {Android 4.3 - JELLY_BEAN_MR2}) then aTmpAvailableSpace := aStatFS.getBlockSize * aStatFS.getAvailableBlocks
  else aTmpAvailableSpace := aStatFS.getAvailableBytes;
  aStatFS := nil;
  {$ELSEIF defined(IOS) or defined(_MACOS)}
  aFileManager := TNSFileManager.Wrap(TNSFileManager.OCClass.defaultManager);
  aDict := aFileManager.attributesOfFileSystemForPath(StrToNSStr(aDir), nil);
  if aDict = nil then aTmpAvailableSpace := 0
  else begin
    aPointer := aDict.objectForKey((CocoaNSStringConst(FoundationFwk, 'NSFileSystemFreeSize') as ILocalObject).GetObjectID);
    if Assigned(aPointer) then aTmpAvailableSpace := TNSNumber.Wrap(aPointer).unsignedLongLongValue
    else aTmpAvailableSpace := 0;
  end;
  {$ELSEIF defined(MSWINDOWS)}
  aDiskDrive := ALupperCaseU(AlStringReplaceU(ExtractFileDrive(aDir), ':', '', []));
  if length(aDiskDrive) = 1 then aTmpAvailableSpace := DiskFree(ord(aDiskDrive[low(aDiskDrive)]) - $40)
  else aTmpAvailableSpace := 0;
  {$ENDIF}

这篇关于如何知道android / ios上的可用磁盘空间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆