SDCard 内容存在但看不到它们 [英] SDCard content exist but cant see them

查看:28
本文介绍了SDCard 内容存在但看不到它们的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的三星 Nexus 和 Android 4.0.2 遇到了非常奇怪的问题.我写了一个简单的程序,它基本上在用户每次按下按钮时创建文件.我的程序在其他设备上运行良好,在 Galaxy Nexus Windows/Mac 上看不到 SD 卡上的这些文件,但是当我执行 adb shell 时,我看到 SD 卡上的所有文件.

I am having very Strange problem with my Samsung Nexus with Android 4.0.2. I wrote a simple program which basically create file each time user presses a button. My program is working great on other devices where as on Galaxy Nexus Windows/Mac can not see those files on SD card, but when i do adb shell i see all files on SD Card.

我在另一个装有 Android 4.0.4 但结果相同的 Nexus 上重新测试.

I retest this on another Nexus which has Android 4.0.4 but still same result.

可能是什么原因?

推荐答案

您可能需要通过 MediaScannerConnection 索引您的文件.引用我自己去年的一篇博文:

You probably need to index your files via MediaScannerConnection. Quoting myself from a blog post from last year:

...MTP 内容不是基于外部存储的文字内容.相反,MTP 内容基于 MediaScannerConnection 扫描的文件.如果您将文件写入外部存储,除非该文件被 MediaScannerConnection 扫描,否则用户将无法通过 MTP 看到该文件.

...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.

在重新启动时扫描外部存储,并且可能会定期扫描.用户可以通过 SDRescan 等实用程序手动强制扫描.但是,最好的答案是在关闭文件后使用 MediaScannerConnection 上的 scanFile() 来更新媒体数据库.这将使您的文件立即可供用户使用.

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.

这篇关于SDCard 内容存在但看不到它们的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆