How to update the file system of SD-card? Windows explorer (and the other programs which open file system) crashes. It shows all files new and deleted.
The method below just updates existing files:
MediaScannerConnection.scanFile (this, new String[] {file.toString()}, null, null);
As I understood below method works just for Android < 4.4 version:
sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED, Uri.parse("file://" + Environment.getExternalStorageDirectory())));
How to update deleted files and folders?
EDITED:
CODE EXAMPLE (creating and removing file):
//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);
}
}