【问题标题】:BroadcastReceiver to listen when a contact added or deleted from favorite/staredBroadcastReceiver 用于在收藏夹/注视中添加或删除联系人时收听
【发布时间】:2016-08-05 13:39:41
【问题描述】:

在收藏夹/已加星标的联系人列表中添加/删除联系人时,是否有办法收听/处理。

我已经检查了onChange()。但它不处理收藏夹/加星标设置。

【问题讨论】:

    标签: android android-contentprovider android-contacts contactscontract


    【解决方案1】:

    有一个默认的联系观察者..希望对你有帮助

    public class MyCOntentObserver extends ContentObserver {
            public MyCOntentObserver() {
                super(null);
            }
    
            @Override
            public void onChange(boolean selfChange) {
                super.onChange(selfChange);
                final int currentCount = getContactCount();
    
                // Get count from your sqlite database
                int mContactCount = getContactOWNCount();
    
                if (currentCount < mContactCount) {
                    // DELETE HAPPEN.
                    Log.e("Status", "Deletion");
                    //contactDBOperaion.SyncContacts(1);
                } else if (currentCount == mContactCount) {
                    // UPDATE HAPPEN.
                    //  contactDBOperaion.SyncContacts(0);
                } else {
                    // INSERT HAPPEN.
                    Log.e("Status", "Insertion");
                    // contactDBOperaion.SyncContacts(2);
                }
                Log.e("", "~~~~~~" + selfChange);
            }
    
            @Override
            public boolean deliverSelfNotifications() {
                return true;
            }
        }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-01-14
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多