注册:在Android的联系方式的变化联系方式、Android

2023-09-07 13:17:43 作者:- 心也死,爱以决

我使用的联系人ContentObserver。但在这里我的问题是,一旦ATLEAST我要发动我的应用程序的其他明智的我是无法得到通知chages。我的code这样的

I am using ContentObserver on contacts. But here my problem is atleast once i have to launch my application other wise i am unable to get notification chages. My code like this

ContactsContentObserver CCO =新ContactsContentObserver(处理);

ContactsContentObserver cco = new ContactsContentObserver(handler);

    ContentResolver contentResolver = getContentResolver();

    contentResolver.registerContentObserver(RawContacts.CONTENT_URI,
    true, cco);

            }

private class ContactsContentObserver extends ContentObserver 
{
 public ContactsContentObserver(Handler h) 
 {
      super(h);
    }

    public void onChange(boolean selfChange) 
    {
       System.out.println("##########SOMEBODAY CHANGED ANYTHING AT THE CONTACTS");
       Toast.makeText(getApplication(),"####Updated####",Toast.LENGTH_LONG).show();


       }

....进阶感谢。

.... Adv thanks.

推荐答案

我假设你是想在 ContentObserver 来自动东西时在联系人改变运行。问题是,什么将需要调用code,它注册了监听器。什么你大概可以做的是建立在设备完成启动启动服务,注册 ContentObserver ,然后退出。该服务并不需要不断的运行的ContentProvider 框架将自动调用您的code。考虑注册接收 BOOT_COMPLETED_ACTION 意图按这篇文章。

I assume you are wanting the ContentObserver to automatically run when something changes in the contacts. The problem is, something will need to call the code that registers that listener. What you probably could do is create a service that starts when the device finishes booting, registers the ContentObserver and then exits. The service does not need to continuously run as the ContentProvider framework will automatically call your code. Look into registering to receive the BOOT_COMPLETED_ACTION intent as per this post.