其他分享
首页 > 其他分享> > android – SDCard内容存在但无法看到它们

android – SDCard内容存在但无法看到它们

作者:互联网

我的三星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,android-sdcard,galaxy
来源: https://codeday.me/bug/20190919/1812327.html