V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
linhaiczy
V2EX  ›  Android

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

  •  
  •   linhaiczy · Dec 2, 2022 · 11983 views
    This topic created in 1254 days ago, the information mentioned may be changed or developed.

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

    2 replies    2022-12-10 13:35:35 +08:00
    TArysiyehua
        1
    TArysiyehua  
       Dec 4, 2022
    android 系统通过媒体库管控所有文件 MediaSotre ,任何公共文件的修改都会同步给它
    linhaiczy
        2
    linhaiczy  
    OP
       Dec 10, 2022
    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()中
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   918 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 33ms · UTC 20:24 · PVG 04:24 · LAX 13:24 · JFK 16:24
    ♥ Do have faith in what you're doing.