SDCard 内容存在但看不到它们

编程入门 行业动态 更新时间:2024-10-26 12:27:18
本文介绍了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 内容存在但看不到它们

本文发布于:2023-11-27 20:34:24,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1639505.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:内容   SDCard

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!