3

I'm curious to know if there's a better way to monitor a directory for file changes/creations/deletions than FileObserver. FileObserver requires a constant reference to it, which requires a constantly running service, which is difficult and a bad practice, right?

I'd appreciate any insight as to how you monitor the filesystem without, say, draining battery or having to keep a service running. (In newer Android versions, the service is killed when you swipe the app off the recent apps stack.)

Thanks!

Osmium USA
  • 1,751
  • 19
  • 37

2 Answers2

0

You could do a timer (alarm) at some interval and get directory listing and check create date or update date (since last check). The last check date/time can be passed into the alarm as an extra.

Dave Truby
  • 193
  • 1
  • 5
0

PS: It's been a long time since you asked the question but maybe the answer will be usefull for others.

You could try to create a kernel module to monitor a directory or a specific file. The targetted events can be written to a file and accessed from user space with an application or service.