android - SD卡内容存在但看不到

标签 android android-sdcard galaxy

我的 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/

相关文章:

android - 列出 SD 卡中的所有图像

android - 三星Note 3 : Activity Memory Leak after pressing SPen side button

android - 如何从 Android Studio 模拟器连接到本地主机

Android 支持库 ActionBar 在 2.3 设备中不起作用

android - 由 : java. lang.IllegalStateException : Unable to create directory in Android 6. 0 设备引起

Android list - 设备兼容性列表,缺少 Galaxy S2

android - Galaxy S2/S3/S4 上的库存短信应用程序包名称?

android - 跨平台移动 C++ SDK 通常如何工作?

来自 PreviewCallback 的 android 相机发布错误

java - 如何在 Android 中写入 SD 卡上的文件夹?