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

2022-12-02 22:00:59 +08:00
 linhaiczy

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

3858 次点击
所在节点    Android
2 条回复
TArysiyehua
2022-12-04 17:07:47 +08:00
android 系统通过媒体库管控所有文件 MediaSotre ,任何公共文件的修改都会同步给它
linhaiczy
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()中

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/899712

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX