FileObserver getting strange events

Viewed 3793

Ok, this is simple: I have a FileObserver class to observe a folder with music. So I implemented onEvent and all that stuff, but when I move or paste a file on that folder using a file manager, instead of getting a FileObserver.MOVED_TO or a FileObserver.CREATE, I'm getting weird events with numbers like 1073741656, that are not documented on: http://developer.android.com/reference/android/os/FileObserver.html

So how do I get those specific events like deleting, moving, creating and pasting?

[edit] Here is the code:

 private class MusicsFileObserver extends FileObserver {

    public MusicsFileObserver(String root) {
        super(root);

        if (!root.endsWith(File.separator)) {
            root += File.separator;
        }
    }

    @SuppressWarnings("unused")
    public void close() {
        super.finalize();
    }

    public void onEvent(final int event, String path) {
      //here is the problem, if you see the documentation, when a file is moved 
      //to this directory, event should be equal to FileObserver.MOVED_TO, 
      //a constant value of 128. But when debugging, instead of entering here one time
      //with event == 128, this method onEvent is being called 4~5 times with event
      //with numbers like 1073741656
        if (event != FileObserver.ACCESS || event != FileObserver.OPEN || event != 32768)
            runOnUiThread(new Runnable() {
                public void run() {
                    rescanMusics();
                }
            });
    }
}
4 Answers
Related