gh123man
gh123man

Reputation: 1414

listening for file changes in android file-system without file observer

I am still new to android programming, (wrote one small app so far) and I am also new to stack overflow. I am looking to write something that will listed for changes in a file, exactly like how file observer works. but the issue is the file im looking at receives changes from the kernel, and i realized that file observer does seem to pick up on changes unless it is done by the user. thanks.

Upvotes: 1

Views: 1669

Answers (3)

gh123man
gh123man

Reputation: 1414

I know this is old, but I figure I should Post the answer I found.

The solution is UEventObserver

doc: (http://www.androidjavadoc.com/1.1_r1_src/android/os/UEventObserver.html)

I found my answer in the "frameworks / base / services / java / com / android / server /" area of the android source code where they listen to changes reported form the kernel.

my implementation of the solution is here: https://github.com/gh123man/ICS_tablet_HW_rotationlock/blob/master/frameworks/base/services/java/com/android/server/RotationSwitchObserver.java

Upvotes: 2

strex
strex

Reputation: 1

"the file im looking at receives changes from the kernel"

If you are referring to file from the procfs, or some other virtual-file, I fear inotify won't help you a lot...

search for "Q: Are there any limitations for use of inotify?"

Q: Are there any limitations for use of inotify?
Yes. Some filesystems (e.g. procfs or some network filesystems) don't emit events in some cases.

Upvotes: 0

Tom
Tom

Reputation: 17854

I believe there is no good solution. FileObserver will only report events that originate in user space - kernel originated events (i.e. to procfs file) are not reported. Further, the File operations won't work either, so you can can't check the hash, length, modified date, etc. of these files.

My observations are based on 2.3.6.

Upvotes: 0

Related Questions