问题描述
我整天都在争夺一些琐碎的东西,但现在我只是放弃了,需要您的帮助.
I lost whole day fighting with something trivial, but now I just give up and need your help.
在用于读取应用程序代码/数据/缓存/大小的新Oreo API中,我们需要存储UUID( StorageStatsManager.queryStatsForUid(UUID storageUuid, int uid)).
In new Oreo API for reading app code/data/cache/ size we need storage UUID (StorageStatsManager.queryStatsForUid(UUID storageUuid, int uid)).
可以从 StorageManager中获取存储UUID. getStorageVolumes()返回所有包含UUID的存储的列表.
The storage UUID is possible to fetch from StorageManager.getStorageVolumes() which returns list of all storages which contains also the UUIDs.
问题开始了,:返回的列表中的UUID为String格式,而 StorageStatsManager.queryStatsForUid(UUID storageUuid, int uid)需要UUID对象-更简单-存在方法 UUID.fromString(字符串名称)会在一段时间内对其进行转换..但是,等等,StorageManager列表中的UUID值与UUID解析器不兼容-什么?! >我检查了2台设备(其中一台使用Oreo,一台使用Nougat),均带有外部存储器,每台设备都有2个存储空间:
And there the problem begins: The UUID from returned list is in String format while StorageStatsManager.queryStatsForUid(UUID storageUuid, int uid) requires UUID object - nothing simplier - there exist method UUID.fromString(String name) which converts it in a while.. but wait, the UUID value from StorageManager list is incompatibile with UUID parser - WHAT?! I've checked on 2 devices (one with Oreo and one with Nougat), both with external memory and for each device I get 2 storages:
- 具有UUID的内部设备内存等于空"-可以很好地满足文档中的描述
- 外部存储卡的UUID值格式为"4012-1A4B",这是无效的UUID格式,并导致UUID.fromString抛出IllegalArgumentException.
- Internal device memory with UUID equals "null" - thats fine as this is described in documentation
- External card storage with UUID value in format like "4012-1A4B" what is invalid UUID format and causes UUID.fromString throws IllegalArgumentException.
谁能向我解释我在做什么错,我应该如何获取用于外部存储的UUID?或者只是新的API StorageStatsManager .queryStatsForUid(UUID storageUuid, int uid)没有用,因为我们无法获取存储UUID?
Can anyone explain me what am I doing wrong and how should I get UUID for external storage? Or just new API StorageStatsManager.queryStatsForUid(UUID storageUuid, int uid) is useless as we are unable to get storage UUID?
仅供参考:
此外,还有另一个StackOverflow问题,其中此API的使用被标记为正确的解决方案: https://stackoverflow.com/a/44708209/1946366 是什么让我更加沮丧...
Whats more there is another StackOverflow question where usage of this API is marked as correct solution: https://stackoverflow.com/a/44708209/1946366 what makes me even more frustrated...
推荐答案
我发现这已经在Android上引发了错误: https://issuetracker.google.com/issues/62982912 所以我认为我的问题无法回答.
I found that this is raised already bug on Android:https://issuetracker.google.com/issues/62982912so I think that my questions is unanswerable.
这篇关于从Android StorageManager获取的存储UUID无效?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!