肮脏的旗帜没有设置为" 1"关于联系人更新

时间:2016-06-24 11:42:23

标签: android android-contacts android-syncadapter android-authenticator

我正在开发一个项目,我想在其中检测联系人中的更改。所以我创建了帐户管理帐户,并尝试使用DIRTY标志在联系人列表中查找更改。但是当联系人更新时,我的app app_type没有设置DIRTY标志。但是另一个account_type(com.google)的DIRTY标志正在设置中。帮我 这就是我在我的帐户和account_type中插入联系人的方式。     public static void addContact(Context context,MyContact contact){     ContentResolver resolver = context.getContentResolver();     boolean mHasAccount = isAlreadyRegistered(resolver,contact.Id);     如果(mHasAccount){         Log.d("已联系","那里");     } else {         Log.d(" new Contact","添加");         的ArrayList< ContentProviderOperation> ops = new ArrayList< ContentProviderOperation>();         //插入帐户名称和帐户类型         ops.add(ContentProviderOperation                 .newInsert(addCallerIsSyncAdapterParameter(ContactsContract.RawContacts.CONTENT_URI,true))                 .withValue(ContactsContract.RawContacts.ACCOUNT_NAME,constants.ACCOUNT_NAME)                 .withValue(ContactsContract.RawContacts.ACCOUNT_TYPE,constants.ACCOUNT_TYPE)                 .withValue(ContactsContract.RawContacts.AGGREGATION_MODE,                         ContactsContract.RawContacts.AGGREGATION_MODE_DEFAULT)                 。建立());         //插入联系电话         ops.add(ContentProviderOperation                 .newInsert(addCallerIsSyncAdapterParameter(ContactsContract.Data.CONTENT_URI,true))                 .withValueBackReference(ContactsContract.Data.RAW_CONTACT_ID,0)                 .withValue(ContactsContract.Data.MIMETYPE,ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE)                 .withValue(ContactsContract.CommonDataKinds.Phone.NUMBER,contact.number)                 。建立());         //插入联系人姓名         ops.add(ContentProviderOperation                 .newInsert(addCallerIsSyncAdapterParameter(ContactsContract.Data.CONTENT_URI,true))                 .withValueBackReference(ContactsContract.Data.RAW_CONTACT_ID,0)                 .withValue(ContactsContract.Data.MIMETYPE,                         ContactsContract.CommonDataKinds.StructuredName.CONTENT_ITEM_TYPE)                 .withValue(ContactsContract.CommonDataKinds.StructuredName.DISPLAY_NAME,contact.name)                 。建立());         //插入mime类型的数据         ops.add(ContentProviderOperation                 .newInsert(addCallerIsSyncAdapterParameter(ContactsContract.Data.CONTENT_URI,true))                 .withValueBackReference(ContactsContract.Data.RAW_CONTACT_ID,0)                 .withValue(ContactsContract.Data.MIMETYPE,MIMETYPE)                 .withValue(ContactsContract.Data.DATA1,12345)                 .withValue(ContactsContract.Data.DATA2," user")                 .withValue(ContactsContract.Data.DATA3," MyData")                 。建立());         尝试{             resolver.applyBatch(ContactsContract.AUTHORITY,ops);         } catch(例外e){             e.printStackTrace();         }     } } 用于检查联系人列表中的更改的代码 private void updateServer(){     Log.d(" Server","更新");     游标光标= mContentResolver.query(ContactsContract.RawContacts.CONTENT_URI,             new String [] {ContactsContract.RawContacts.DIRTY,ContactsContract.RawContacts.CONTACT_ID,ContactsContract.RawContacts.ACCOUNT_TYPE},             ContactsContract.RawContacts.DIRTY +" =? &#34 ;,             new String [] {String.valueOf(1)},             空值);     if(cursor!= null&& cursor.getCount()> 0)     {         cursor.moveToFirst();         而(!cursor.isAfterLast()){             String id = cursor.getString(cursor.getColumnIndex(ContactsContract.RawContacts.CONTACT_ID));             String dirty = cursor.getString(cursor.getColumnIndex(ContactsContract.RawContacts.DIRTY));             String type = cursor.getString(cursor.getColumnIndex(ContactsContract.RawContacts.ACCOUNT_TYPE));             if(id!= null&& dirty!= null&& type!= null){                 Log.d(" Upadte Dirty",脏);                 Log.d("更新ACCountid",id);                 Log.d("更新类型",类型);                 Cursor cur = mContentResolver.query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI,                         new String [] {ContactsContract.CommonDataKinds.Phone.NUMBER,ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME},                         ContactsContract.CommonDataKinds.Phone.CONTACT_ID +" =?",                         new String [] {String.valueOf(id)},                         空值);                 if(cur!= null&& cur.getCount()> 0){                     cur.moveToFirst();                     而(!cur.isAfterLast()){                         String name = cur.getString(cur.getColumnIndex(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME));                         字符串编号= cur.getString(cur.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));                         Log.d("更新名称",名称);                         Log.d("更新号码",号码);                      / * ContactsManager.updateContact(getContext(),id,name,number);                         CV.clear();                         CV.put(DBconstants.TableConstants.PHONE_NUMBER,number);                         CV.put(DBconstants.TableConstants.C_CONTACT_NAME,姓名);                         DB.updateInformation(DB,DBconstants.TableConstants.TABLE_CONTACTS,CV,DBconstants.TableConstants.C_ID,id);                         CV.clear();                     * / cur.moveToNext();                     }                     cur.close();                 }其他{                     Log.d(" Serverupdate"," nullinvalues");                 }             }其他{                 Log.d(" Serverupdate"," nullvalues");             }             cursor.moveToNext();         }         cursor.close();     } else {         Log.d(" Serverupdate"," nullcursor");     } }

0 个答案:

没有答案