title: Watch for changes in external USB storage for Honeycomb or later Android versions
body: <p>I've got a DSLR camera and Samsung Galaxy Tab running Android Honeycomb. DSLR connected to a tablet using USB-cable (via USB kit enabling host functionality on a tablet). I'd like to being notified when user takes a photo using this external camera, in order to download this image to the tablet or do something else with it like showing Toast notification containing meta-information taken from the image.</p>
  
  <p>As far as I get all of the existing tools (like <code>FileObserver</code> using underlying <code>inotify</code> mechanism, <code>MediaContentProvider</code> etc)  allowing to watch for changes, demand a specific file or a filesystem path to be watched. This was good enough till we had a block layer protocol support in 2.x and earlier Android versions - when you connected device it'd been mounted somewhere on the device's filesystem and you was able to use this mountpoint as a watch point for those tools. </p>
  
  <p>Since Honeycomb Google has changed the way of accessing external USB devices to <code>Media Transfer Protocol</code> with <code>PTP</code> as a subset of this. Now when I connect external USB device to an Android device I won't see any mountpoints for it (I'm using <code>adb shell</code> and subsequent <code>mount</code> command for getting them). Moreover, <code>MTP</code> implementation uses storage ids which apparently act as a higher level of abstraction and are just plain integer values. I was hoping there is a way to somehow translate these storage ids to the real paths/mountpoint/whatever but apparently there does not appear to be. </p>
  
  <p>Thinking about Android <code>MediaScanner</code> which is already running on my device I guessed it could manage this issue with a special <code>Intent</code> broadcasted when there're changes in media files accessible from the device, so I started looking for already existing and suitable <code>Intents</code> for being notified, but no luck - I found only <code>ACTION_MEDIA_MOUNTED</code> and <code>ACTION_MEDIA_REMOVED</code> which are broadcasted only when device is connected and disconnected respectively. That means <code>MediaScanner</code> can't notice any changes on the device until you remount it (I've double checked it using stock Gallery app - it doesn't see any newly created images on the camera until you unplug and then plug it into the Android device again). </p>
  
  <p>Trying to get this mount path for external sdcard, I used <code>Environment.getExternalStorageDirectory()</code> API call but it yields emulated Galaxy's sdcard path
  which is <code>/mnt/sdcard</code>, not the camera's one. So it doesn't work for me either. </p>
  
  <p>I managed to work out this issue only having launched periodic <code>Timer</code> event with <code>AsyncTask</code> acting as a <code>TimerTask</code>. This task does initialize usb connection, open device,
   scan the whole device memory, getting only the last taken photo and then close device descriptor and usb connection. </p>
  
  <p>It doesn't look like the best and efficient way  of doing that taking into account it has to do all of these actions every time which could be pretty often, say each 5 or 10 seconds. It definitely quickly drains battery out and produces unnecessary system I/O for only taking last taken photo and comparing it with the previous last taken photo (in 99% it'd the same image), but I haven't found any better working solution for doing this. It'd much better off to have an observer mechanism with event-based notifications.</p>
  
  <p>So my question is there more efficient way of being notified about changes in external USB storage for Honeycomb or later Android versions rather than one described above? </p>