删除后,Windows不会刷新Android设备SD卡上的文件

时间:2014-07-01 06:59:52

标签: java android sd-card android-sdcard

如何更新SD卡的文件系统? Windows资源管理器(以及打开文件系统的其他程序)崩溃。它显示所有新文件和已删除的文件。

以下方法只更新现有文件:

MediaScannerConnection.scanFile (this, new String[] {file.toString()}, null, null);

据我所知,下面的方法适用于Android< 4.4版本:

sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED, Uri.parse("file://" + Environment.getExternalStorageDirectory())));

如何更新已删除的文件和文件夹?


编辑:

代码示例(创建和删除文件):

//i'm createing the file:
//in works properly!
File file = new File(dir, "filename.pos");
os = new DataOutputStream(new FileOutputStream(file));
os.writeLong(versionOfPOSFile);
os.close();
MediaScannerConnection.scanFile (context, new String[] {file.toString()}, null, null);



//this code deletes a file:
//it doesn't work!
//files are not updated in Windows.
File path = /*some folder path*/
File[] c = path.listFiles();
 for (File file : c){
file.delete();
//even I add this code:
MediaScannerConnection.scanFile(context, new String[] {file.toString()}, null, null);
}
}

0 个答案:

没有答案