Search code examples
androidvideoandroid-4.2-jelly-beanfileobserver

Android jelly bean sends a CLOSE_WRITE event when a video starts instead of just when finished


My code listens to the DCIM folder, using a FileObserver.

All Android versions I used, except 4.1.1, sent only 1 event - when the video was finished taken. I think it's the correct behavior - write continually and close when finished.

In 4.1.1 (Galaxy Nexus and Nexus S) though, the event FileObserver.CLOSE_WRITE is sent twice - when the video starts and when it ends.

Also the same for photos - the event is sent twice - though it's not that critical.

The problem is that I can't distinguish between the start event and end event of a video.

I could try and check the size of the file, but because the event may have been delayed (slow/busy device), the size may be quite big.

Any idea why was the behavior changed? Do you know where is the camera's app source code? I can try and look at the history to understand that.


Solution

  • As I wrote in one of my comments, the difference between 4.1 and previous Android versions is that in 4.1.1, the file is written and closed twice. Once when an empty video file is created. Then the video is written into a tmp file. Then the rename/copy of the tmp file is the second write_close event.

    In previous versions there's not tmp file - only the original - thus only one close_write event.

    Please comment if you think it's a bug. I'm not sure.