V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
linhaiczy
V2EX  ›  Android

安卓不同文件类型占用空间统计如何实现

  •  
  •   linhaiczy · 2022-12-02 22:00:59 +08:00 · 3236 次点击
    这是一个创建于 482 天前的主题,其中的信息可能已经有所发展或是发生改变。

    比如文件管理器中的,各种类型的数据占用大小 系统 x.xGB 应用数据 x.xGB 视频 图片 其他 可用空间 这个在安卓中该如何统计

    2 条回复    2022-12-10 13:35:35 +08:00
    TArysiyehua
        1
    TArysiyehua  
       2022-12-04 17:07:47 +08:00
    android 系统通过媒体库管控所有文件 MediaSotre ,任何公共文件的修改都会同步给它
    linhaiczy
        2
    linhaiczy  
    OP
       2022-12-10 13:35:35 +08:00
    ong totalBytes = storageStatsManager.getTotalBytes(uuid);
    long freeBytes = storageStatsManager.getFreeBytes(uuid);
    StorageStats storageStats = storageStatsManager.queryStatsForUser(uuid, user);
    long appBytes = storageStats.getAppBytes();
    long dataBytes = storageStats.getDataBytes();
    ExternalStorageStats externalStorageStats = storageStatsManager.queryExternalStatsForUser(uuid,user);
    long totalExternalUsedBytes = externalStorageStats.getTotalBytes();
    long imageBytes = externalStorageStats.getImageBytes();
    long audioBytes = externalStorageStats.getAudioBytes();
    long videoBytes = externalStorageStats.getVideoBytes();

    long appsSize = Utils.sub(Utils.add(appBytes, dataBytes).longValue(), totalExternalUsedBytes).longValue();
    long otherSize = Utils.sub(totalExternalUsedBytes, imageBytes, audioBytes, videoBytes).longValue();
    long dataSize = Utils.add(appBytes, dataBytes, freeBytes).longValue();
    long system = Utils.sub(totalBytes, dataSize).longValue();
    其中 appsSize 是计算的所有应用大小

    目前是这么获取的,但总感觉有点问题
    在用 adb 内存填充后,生成的文件会被统计到 storageStats.getDataBytes()中
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   994 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 22ms · UTC 20:06 · PVG 04:06 · LAX 13:06 · JFK 16:06
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.