安卓 USB 大容量存储
所以,我知道如何检测 USB 大容量存储的连接和断开。到目前为止,一切都很好。
但现在我遇到了一个问题,一旦我在应用程序中退出 USB 模式,MediaStore 就会开始扫描媒体,我等待扫描完成,然后尝试从 MediaStore 访问一些内容。我存储图像和视频的 ID,并在扫描完成后尝试获取这些项目的 URI。
但现在,当我使用所存储的 ID 查询这些文件的 URI 时,某些文件的 URI 显示为 null。这就是我的问题,因为他们不应该这样。
有人指出我缺少什么吗?
So, I know how to detect USB mass storage being connected and disconnected. So far so good.
But now I have a problem, wherein once I get out of USB mode in my app, MediaStore begins to scan media, I wait for that scanning to be complete, and then I try to access some content from MediaStore. I store the ID of images and videos and try to get the URI of those items once scanning is complete.
But now when I query for the URI of those files with the stored ID I have, some of the files' URIs come out as null. And that's my problem, because they shouldn't be.
Does anyone have pointers as to what I am missing?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
USB 模式切换后,当用户退出 USB 模式时,Mediastore 会进行扫描,并且在此过程中,它会枚举与之前不同的 ID。不知道为什么,但我比较了同一张图片,它的 ID 似乎与以前不同。并不总是发生,但可能会也可能不会。所以我需要等待扫描完成并更新我存储的 ID。这似乎可以解决问题
after USB mode Switching, When a USER comes out of USB mode, Mediastore does the scanning and in process, it happens to enumerate the ID's differently than it did before. Not sure why, but i compared same image and it seemed to have different ID than it had before. Doesn't happen always but it may or may not. So i needed to wait for scan to finish and update the ID's i was storing. That seems to solve the issue