注册:在Android的联系方式的变化 [英] Reg : Contact changes in Android

查看:107
本文介绍了注册:在Android的联系方式的变化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的联系人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 意图按<一个href=\"http://markmail.org/message/7r6afkcusvwe2wfz#query%3aandroid%20auto%20start%20service+page:1+mid%3auee3n7yjip6nsmfr+state%3aresults\"相对=nofollow>这篇文章。

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.

这篇关于注册:在Android的联系方式的变化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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