Ron
Ron

Reputation: 369

Android FileObserver with weird events

In Android FileObserver i am getting some weird event numbers like (1073742080, 1073742336) when a directory is created in the observed folder or a directory is deleted in that folder.

I am getting these event numbers consistently for folder creation and deletion. But these event numbers are not documented in FileObserver class of Android.

Can someone please explain why i am receiving this weird event only during folder creation and not on file creations? And is there any way to avoid this problem.

-Ron

Upvotes: 3

Views: 1130

Answers (2)

Stephan Shere
Stephan Shere

Reputation: 328

1073742080 is representing the code for a IN_CREATE: "A file or folder was created in the watched directory."

It seems that 0x4xxx codes represent directory events based off the inotify headers provided by mvsjes2 as commented on line 56 of inotify.h: #define IN_ISDIR 0x40000000 /* event occurred against dir */

More information, which has been provided by another user who has documented the codes from his use-cases can be found here: http://php.net/manual/en/function.inotify-read.php

Upvotes: 2

mvsjes2
mvsjes2

Reputation: 1274

I found the MOVED_TO and MOVED_FROM events have high-order bits turned on in the event flag. MOVED_FROM is 0x40000040 and MOVED_TO is 0x40000080. The workaround is to simply 'and' ALL_EVENTS with the event code to turn off the high bits, i.e. "event &= FileObserver.ALL_EVENTS".

Upvotes: 6

Related Questions