0

I want to observe the changes in a directory mostly the new file creations, So I am using this methods described here - https://www.darshanpandya.cf/blog/fileobserver-is-kinda-dead-whats-the-alternative/

My point is, if I use the methods above in a continuous service like calling BroadcastReceiver from Service's onDestroy() & starting the service again from BroadCastReceiver's onReceive(), will there be an excessive battery drain?

Darshan
  • 4,020
  • 2
  • 18
  • 49

1 Answers1

0

You can use FileObserver class available from API level 1.

observer = new FileObserver(pathToWatch) { // set up a file observer
  @Override public void onEvent(int event, String file) {
     Toast.makeText(getBaseContext(), file + " was saved!", Toast.LENGTH_LONG).show();
   }
};
observer.startWatching(); //START OBSERVING 

Another example on Gist.
See also this StackOverflow post

riyaz-ali
  • 8,677
  • 2
  • 22
  • 35