I have FileObserver's hooked onto a particular directory in /mnt/sdcard/X and its descendants recursively. When I modify contents of this directory from the phone itself (say from the Gallery app), the onEvent() of my FileObserver is correctly called and everything works fine.

When I connect via USB to a computer and switch to mass storage mode, all changes done via the computer to the same directory are not translated to events to the FileObserver. Is there a limitation on the FileObserver that it will not work in USB mass storage?

I tried an 'adb push xx /mnt/sdcard/X/xx' and this change gets recorded correctly too.

有帮助吗?

解决方案

Is there a limitation on the FileObserver that it will not work in USB mass storage?

Nothing in Android works with external storage when it is mounted via USB Mass Storage (Android 1.x/2.x). The external storage is exclusively owned by the OS that has it mounted. You will not get FileObserver events while the storage is so mounted.

Android 3.0+ uses the Media Transfer Protocol (MTP) instead of USB Mass Storage, and so FileObserver should work with external storage on newer versions of Android, even while another OS has access to that storage.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top