1

Does someone know is there a way I can get notified on file change in /proc/uid_stat/myAppUID folder? I want to track data usage of my app. The file is there and when I read it manually using BufferedReader, I get the data traffic.

I tried using FileObserver class and also RecursiveFileObserver but I don't get any callback when data usage change. My guess is that it doesn't work on virtual file system. I would like to get notified from linux when these files changes, because looping constantly through files is not a valid option for me. Here is the code I used:

path = "/proc/uid_stat/"+getApplicationInfo().uid;
observer = new FileObserver(path) { 
         @Override
         public void onEvent(int event, String file) {
             Toast.makeText(getApplicationContext(), file + " was changed!", Toast.LENGTH_LONG).show();
             }
         }
     };
     observer.startWatching();
4

0 回答 0