title: How can I monitor another application's database for changes?
body: <p>I'd like to monitor changes to another applications SQLite database. Since the Android doesn't allow me to access another application's internal data, I need a root application which is exactly what mine is.</p>
  
  <p>Is there a way I could monitor changes to a file on the system and trigger an event in my application?</p>
  
  <p>I've Googled around and seen people recommend using <a href="http://developer.android.com/reference/android/os/FileObserver.html" rel="nofollow noreferrer"><code>FileObserver</code></a> class but this wouldn't work for protected files. Any other suggestions?</p>
  
  <p>--</p>
  
  <p>I've been looking for answer for this but I haven't found any. I've tried these two sei-promising techniques but I couldn't get them to work.</p>
  
  <ol>
  <li>All the files in an application's data directory are owned by that application's user and group. <code>FileObserver</code> respects Linux permissions and therefore I can't seem to use it to monitor a database/file in another application's data directory.</li>
  </ol>
  
  <p>I'm wondering if this was possible if I could somehow elevate my application's Linux process to run as <code>root</code>. This isn't easy either as it would mean toying with the <code>setuid</code>, <code>setguid</code> mechanism which I don't have much idea about.</p>
  
  <ol start="2">
  <li>I tried creating a symbolic link from the other application's database file into my application's data directory. I added all permissions on the symbolic link and then used <code>FileObserver</code> to monitor it but this didn't work either. Maybe I did something wrong but my best guess that <a href="https://superuser.com/questions/303040/how-do-file-permissions-apply-to-symlinks/303054#303054">in Linux, symbolic-link permissions are useless</a>. The permissions on a symbolic link that are respected are that of the target file/directory.</li>
  </ol>
  
  <p>There might be way using JNI and the <code>inotify.h</code> files but I'm not sure about how to go about this.</p>
  
  <p>I don't want to poll the database from my application. I'd like to have an event trigger mechanism.</p>