androidfileobserver

Why FileObserver not working for /data/anr/traces.txt?


Android application have read/write permission for /data/anr/traces.txt. But still FileObserver does not seem to work for it.

What else is required for FileObserver to work? It works fine for sdcard file.

Code:

mFileObserver = new FileObserver("/data/anr/traces.txt") { // set up a file observer to
                @Override
                public void onEvent(int event, String file) {
                    if(event == FileObserver.CLOSE_WRITE)
                    {
                        Log.e("TestApp", "ANR has occured");
                    }
                }
            };
            mFileObserver.startWatching();

Solution

  • Found solution to it therefore answering my own question as it may help others.

    Looks like using complete file path "/data/anr/traces.txt" is not working. But using path to "/data/anr" is working ok.

    Still not sure why complete path doesn't work.