title: Persistant contact id
body: <p>I know on some phones contact ids change even on reboot, but I can't reproduce this on my own phone. But I can reproduce following case and would like to know if this case is solveable at least:</p>
  
  <ul>
  <li>install whatsapp - it will add it's contacts to the <code>ContentProvider</code></li>
  <li>read contacts from <code>ContactProvider</code> => I get <strong>data set 1</strong></li>
  <li>delete whatsapp, reinstall it - it will add it's contacts to the <code>ContentProvider</code> again</li>
  <li>read contacts from <code>ContentProvider</code> => I get <strong>data set 2</strong></li>
  </ul>
  
  <p><strong>Result:</strong></p>
  
  <p>Between data set 1 and data set 2 I don't see any consistent data.</p>
  
  <p>E.g.:</p>
  
  <p><code>ContactsContract.Data.CONTACT_ID</code> => changes, e.g. from <code>598</code> to <code>679</code>
  <code>ContactsContract.Data.LOOKUP_KEY</code> => changes as well, e.g. <code>3514i2b4948808eec75c9.3789r593-2D374B39.2797r594-2D374B39</code> to <code>3514i2b4948808eec75c9.2797r603-2D374B39.3789r670-2D374B39</code>
  * of course, some <code>raw ids</code> stay the same, but no common id for a full contact stays the same as far as I can see</p>
  
  <p><strong>What I want</strong></p>
  
  <p>I need an identifier for a contact that I can persistent in my app's database and that will also work after a change like the one described above. <strong>I need an identifier for a contact (not a raw contact), raw contacts may change of course during the lifetime of a contact (like in the example I describe above)...</strong></p>
  
  <p>Any ideas how I can solve this problem?</p>
  
  <p><strong>Code</strong></p>
  
  <p>For the sake of completeness, here's how I query the data from the <code>ContentProvider</code>, at least the cursor:</p>
  
  <pre><code> private fun getCursor(offset: Int?, count: Int?): Cursor? {
      val selection = arrayOf(
              ContactsContract.Data.RAW_CONTACT_ID,
              ContactsContract.Data.CONTACT_ID,
              ContactsContract.Data.LOOKUP_KEY,
              ContactsContract.Data.PHOTO_ID,
              ContactsContract.Data.DISPLAY_NAME,
              ContactsContract.Data.ACCOUNT_TYPE_AND_DATA_SET,
              ContactsContract.CommonDataKinds.Email.DATA,
              ContactsContract.CommonDataKinds.Phone.NUMBER,
              ContactsContract.CommonDataKinds.Phone.TYPE,
              ContactsContract.CommonDataKinds.Phone.LABEL,
              ContactsContract.Contacts.Data.MIMETYPE,
              ContactsContract.RawContacts.ACCOUNT_NAME,
              ContactsContract.CommonDataKinds.Phone.IS_PRIMARY,
              ContactsContract.Data.CONTACT_LAST_UPDATED_TIMESTAMP,
              ContactsContract.RawContacts.SOURCE_ID
      )
  
      return AppProvider.get().context.contentResolver.query(
              ContactsContract.Data.CONTENT_URI,
              selection, null, null,
              ContactsContract.Data.CONTACT_ID + " ASC" + if (offset != null &amp;&amp; count != null) " limit $count offset $offset" else "")
  }
  </code></pre>