如何监控更改另一个应用程序的数据库? [英] How can I monitor another application's database for changes?

查看:212
本文介绍了如何监控更改另一个应用程序的数据库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想监视切换到另一个应用程序SQLite数据库。由于Android不容许我访问其他应用程序的内部数据,我需要一个根的应用程序,这正是我的是。

有没有一种方法,我可以监视更改的文件系统上,并在我的应用程序触发一个事件?

我GOOGLE了四周,看到有人推荐使用<一个href="http://developer.android.com/reference/android/os/FileObserver.html"><$c$c>FileObserver类但这并不受保护的文件。任何其他建议?

-

我一直在寻找这个答案,但我还没有发现任何。我已经试过这两个SEI-有前途的技术,但我不能让他们的工作。

  1. 所有的应用程序的数据目录中的文件是由该应用程序的用户和组拥有。 FileObserver 尊重Linux权限,因此,我似乎无法用它来监控数据库/文件中的另一个应用程序的数据目录。

我不知道这是可能的,如果我能以某种方式提高我的应用程序的Linux进程为运行。这也不容易,因为这将意味着与我没有太多的的setuid setguid 机制玩弄观念有关。

  1. 在我尝试创建从其他应用程序的数据库文件的符号链接到我的应用程序的数据目录。我添加了所有权限的符号链接,然后用 FileObserver 来进行监控,但这也不能工作。也许我做错了什么事,但我最好的猜测,<一个href="http://superuser.com/questions/303040/how-do-file-permissions-apply-to-symlinks/303054#303054">in Linux的符号链接的权限也没用。上受到尊重的符号链接的权限是目标文件/目录。

有可能是一种使用JNI和 inotify.h 文件,但我不知道如何去了解这一点。

我不想轮询从我的应用程序的数据库。我想有一个事件触发机制。

解决方案

您无法从Java访问它。

一种方式是投票:运行 ls -l命令/data/data/com.target.app/databases/data.db ,并定期获得时间戳<。 / P>

也许使用命令。

可能是一个后台服务可以运行这一点,并发出本地广播。

另一种方式是船<一个href="http://android.stackexchange.com/questions/5053/where-can-i-obtain-an-sqlite3-command-line-binary-for-android-2-2-1">SQLite3二进制与您的应用程序,启动程序以root身份,并供应命令它的。我认为像二许多应用程序等,做到这一点。

更新: 下面是一个SQLite3的项目: HTTP://$c$c.google.com/p/sqlite3-android/

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.

Is there a way I could monitor changes to a file on the system and trigger an event in my application?

I've Googled around and seen people recommend using FileObserver class but this wouldn't work for protected files. Any other suggestions?

--

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.

  1. All the files in an application's data directory are owned by that application's user and group. FileObserver respects Linux permissions and therefore I can't seem to use it to monitor a database/file in another application's data directory.

I'm wondering if this was possible if I could somehow elevate my application's Linux process to run as root. This isn't easy either as it would mean toying with the setuid, setguid mechanism which I don't have much idea about.

  1. 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 FileObserver to monitor it but this didn't work either. Maybe I did something wrong but my best guess that in Linux, symbolic-link permissions are useless. The permissions on a symbolic link that are respected are that of the target file/directory.

There might be way using JNI and the inotify.h files but I'm not sure about how to go about this.

I don't want to poll the database from my application. I'd like to have an event trigger mechanism.

解决方案

You can't access it from Java.

One way is poll: to run ls -l /data/data/com.target.app/databases/data.db and get time-stamp periodically.

Or perhaps use watch or tail commands.

May be a background service can run this and issue a local broadcast.

Other way is to ship SQLite3 binary with your app, start process as root, and supply commands to it. I think many apps like titanium etc, do this.

Update: Here's an SQLite3 project: http://code.google.com/p/sqlite3-android/

这篇关于如何监控更改另一个应用程序的数据库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆