简体   繁体   中英

How can I get a contact's version or modified time?

I'm trying to figure out if there is a property in Android contacts that states if a contact has been modified.

I read that it was possible to read a contact's version via the field ContactsContract.Contacts.Entity.VERSION, but I wasn't able to retrieve its value. I always get an IllegalArgumentException.

Does someone know how to get the contact's version or if there is another way to find out if a contact has been modified since the last scanning of the address book?

Heres the code, I havent tested it, as I was busy with my work.

    public void getVersion() {
    //specify which fields of RawContacts table to be retrieved.
    String[] projection = new String[] {RawContacts.VERSION};

    //query the RawContacts.CONTENT_URI
    Cursor cur = mContext.getContentResolver().query(RawContacts.CONTENT_URI, projection,null,null,null);

  while(cur.moveToNext()){
    String version = cur.getString(cur.getColumnIndex(RawContacts.VERSION));    
    Log.i("VersionRetriever", version);
   }

  //Always remember to close the cursor. Otherwise it leads to side-effects.
  cur.close();

}

尝试RawContacts.CONTACT_STATUS_TIMESTAMP而不是RawContacts.VERSION。

如果您想知道特定数据类型(如电话或名称)是否已更改,则可以检查Data.DATA_VERSION(但在Data.CONTENT_URI上)。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM