我的 Samsung Nexus Android 4.0.2 出现了非常奇怪的问题。我写了一个简单的程序,基本上每次用户按下按钮时都会创建文件。我的程序在其他设备上运行良好,因为在 Galaxy Nexus Windows/Mac 上无法看到 SD 卡上的这些文件,但是当我执行 adb shell 时,我看到了 SD 卡上的所有文件。
我在另一个装有 Android 4.0.4 的 Nexus 上重新测试了这个,但结果仍然相同。
可能是什么原因?
最佳答案
您可能需要通过 MediaScannerConnection
索引您的文件。引用我自己 from a blog post from last year :
...the MTP contents are not based on the literal contents of external storage. Instead, MTP contents are based on what files have been scanned by MediaScannerConnection. If you write a file to external storage, until and unless that file is scanned by MediaScannerConnection, it will not be visible to users over MTP.
External storage is scanned on a reboot and possibly on a periodic basis. Users can manually force a scan via utilities like SDRescan. However, the best answer is for you to use scanFile() on MediaScannerConnection to update the media database after you close your file. This will make your file immediately available to the user.
关于android - SD卡内容存在但看不到,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10643476/