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.

相关文章

AdvserView.java package com.earen.viewflipper; import an...
ImageView的scaleType的属性有好几种,分别是matrix(默认)...
文章浏览阅读8.8k次,点赞9次,收藏20次。本文操作环境:win1...
文章浏览阅读1.2w次,点赞15次,收藏69次。实现目的:由main...
文章浏览阅读3.8w次。前言:最近在找Android上的全局代理软件...
文章浏览阅读2.5w次,点赞17次,收藏6次。创建项目后,运行项...