在USB大容量存储模式连接(通过电话),当SD卡数据有时没有看到PC [英] SD card data sometimes NOT seen on PC when connected in USB mass storage mode (via phone)
问题描述
可能重复:结果
SD卡的内容存在,但不能看到他们
手机插入SD卡运行Linux内核(2.6.31)。
Phone running Linux Kernel(2.6.31) with SD card inserted.
[问题]当数据被写入到SD卡(写入系统调用)的写入成功返回。然而,当卡(通过电话),为在计算机上的大容量存储设备被访问时,该数据是没有看到
[ISSUE] When data is written to SD card (write syscall) the write returns successfully. However, when the card (via phone) is accessed as a mass storage device on PC, the data is not seen.
只有在物理上取出卡并重新插入,然后访问它在PC上作为大容量存储装置将显示该被写入的数据。
写入数据后试图FSYNC()。它仍然不会显示。
Only after physically removing the card and reinserting it and then accessing it on PC as a mass storage device will show the data that was written. Tried fsync() after writing the data. Still it wont show.
是内核维护数据写入SD卡前缓存?如果是这样,我怎么确保它被刷新到SD卡?
Is the kernel maintaining a cache before writing the data to SD card? If so, how do I make sure it is flushed to the SD card?
推荐答案
您的问题是的 SD卡的内容存在,但不能看到他们 - 从MTP接口返回的计算机显示内容
Your problem is an exact duplicate of SDCard content exist but cant see them - the PC is displaying the content as returned from the MTP interface.
存根code做你需要做的是什么文件显示:
Stub code to do what you need to make the file appear:
进口:
import android.media.MediaScannerConnection;
import android.os.Environment;
import android.util.Log;
import java.io.File;
存根code:
File f = new File(Environment.getExternalStorageDirectory().getPath() + "/hello_nurse.txt");
if (! f.exists()) {
try {
f.createNewFile();
String[] files = new String[1];
files[0] = Environment.getExternalStorageDirectory().getPath() + "/hello_nurse.txt";
String[] mimes = new String[1];
mimes[0] = "text/plain";
MediaScannerConnection.scanFile(getApplicationContext(), files, mimes, null);
} catch (Exception ex) {
Log.e("SD Create", "Failed to create file", ex);
return;
}
} else {
Log.e("SD Create", "File is already present");
}
这篇关于在USB大容量存储模式连接(通过电话),当SD卡数据有时没有看到PC的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!