挂了一些常规任务?

时间:2011-01-24 13:40:31

标签: android hook

我想知道以下是否可行:

我的应用(服务)保留在后台,并在用户

时被触发
  • 添加/删除/更新联系人
  • 安装/卸载应用
  • 在FS上添加/删除/重命名文件
你觉得这有可能吗? (当然,以适当的方式,如果有可能通过黑客和脏东西来做到这一点)

我试图稍微查看一下互联网,但没有找到与此相关的讨论。

你的猜测是什么?

2 个答案:

答案 0 :(得分:3)

我自己没有尝试过这些,但是:

http://mylifewithandroid.blogspot.com/2008/03/observing-content.html似乎涉及检测联系人数据的变化。基本上,您需要注册ContentObserver并处理您收到通知的更改。

签出http://developer.android.com/reference/android/content/Intent.html - 您可以注册一个BroadcastReceiver,以获得有关正在安装或卸载的应用程序的通知。查找ACTION_PACKAGE_ADDEDACTION_PACKAGE_REMOVED

请参阅How to detect file or folder changes in Android?了解如何检测文件系统中文件的更改时间。您可能仅限于使用FileObserver的沙箱,我不确定。此外 - 似乎没有明确通知重命名,但您可能会从MOVED_FROM后跟MOVED_TO或可能DELETE后跟CREATE <检测到它/ p>

答案 1 :(得分:1)

在SDK版本5 +的SDK示例中找到:

     /**
     * Retrieves the contact information.
     */
    @Override
    public ContactInfo loadContact(ContentResolver contentResolver, Uri contactUri) {
        ContactInfo contactInfo = new ContactInfo();
        long contactId = -1;

        // Load the display name for the specified person
        Cursor cursor = contentResolver.query(contactUri,
                new String[]{Contacts._ID, Contacts.DISPLAY_NAME}, null, null, null);
        try {
            if (cursor.moveToFirst()) {
                contactId = cursor.getLong(0);
                contactInfo.setDisplayName(cursor.getString(1));
            }
        } finally {
            cursor.close();
        }

        // Load the phone number (if any).
        cursor = contentResolver.query(Phone.CONTENT_URI,
                new String[]{Phone.NUMBER},
                Phone.CONTACT_ID + "=" + contactId, null, Phone.IS_SUPER_PRIMARY + " DESC");
        try {
            if (cursor.moveToFirst()) {
                contactInfo.setPhoneNumber(cursor.getString(0));
            }
        } finally {
            cursor.close();
        }

        return contactInfo;
    }

您可以使用Cursor cursor = contentResolver.query(contactUri, new String[]{Contacts._ID, Contacts.DISPLAY_NAME}, null, null, null);指定要进行检索的联系人列。http://developer.android.com/reference/android/provider/ContactsContract.Contacts.html中描述了列名称并查看示例,此处cursor.getLong(0)似乎是您的联系人ID正在寻找。它似乎也是不稳定的,这取决于联系人的编辑方式以及其他人的添加方式,但是你也会抓住这些,所以你应该能够处理这些情况。

相关问题