4

Updated nexus 5 to 4.4.3.

Fileobserver not working for any directory . I tried 1./data/data/com/whatsapp , 2.sdcard/Movies and also 3. "/". Before the update it was working fine.

I saw the RecursiveFileObserver on github and used it along with my fileobserver. When both are used together , then onEvent of my FileObserver is called which is quite wierd. After some time a ANR pops up.

So, how to use fileobserver in android 4.4.3

Here is my code

FileObserver observer = new FileObserver("/data/data/com.whatsapp/databases") {  
     public void onEvent(int event, String file) {
         Log.i("ASH", "path VSLLED");
       Log.i("ASH", "path AXCCESSED     " + file);
      }
    };
    observer.startWatching();

and the link for the RecursiveFileObserver https://github.com/bartoszprzybylski/owncloud-android/blob/master/src/com/owncloud/android/utils/RecursiveFileObserver.java

Btw, the FileObserver is running on a Service

2 Answers2

4

I was able to get FileObserver to work on the KitKat only by adding uses-permission android.permission.WRITE_EXTERNAL_STORAGE to the manifest. I don't know why this permission became necessary from 4.4 version of Android, and probably it is needed only if you're going to monitor external storage. Unfortunately, I couldn't find any documentation or information about this behaviour change.

Roman Petrenko
  • 1,052
  • 1
  • 9
  • 21
0

argument to FileObserver is pointing to Application internal storage. So, give location using context.getDir/getFilesDir. it may help.