I'm using a FileObserver to watch a folder in android. When a user modifies or creates a new file in this folder, the FileObserver should do some stuff with this file.
The thing is that with the use of the clause FileObserver.MODIFY, every time I create/modify a file in this watched folder, the FileObserver method onEvent() is called twice. This is a problem for me because it ruins everything I do afterwards (it's done twice).
This is my code:
mFileObserver = new FileObserver(directoryPath, FileObserver.MODIFY){
public void onEvent(int event, String fileName){
if (event == FileObserver.MODIFY){
// some stuff to do
}
}
};
FileObserver.CLOSE_WRITE is triggered when a file that was just written to is closed. You just need to check for that event only.
public void onEvent(int event, String fileName){
if (event == FileObserver.CLOSE_WRITE){
// some stuff to do
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With