title: Storing and retrieving contacts in android
body: <p>I've got a contact picker in my app which returns a contact and from that I'm storing several bits of information into sharedPreferences. In the shared preferences I'm using the lookup key to hold the data (as the android docs seem to suggest)</p>
  
  <p>This part all seems fine and I get and store the lookup key.</p>
  
  <p>My problem is then went I come to getting back the contacts looking up the contact via the lookup key sometimes seems to return null</p>
  
  <p>The following details come from the contact picker</p>
  
  <pre><code> Contact lookup key from the contact picker: 850i%2bw7vj56otre6eqa9b9t7wa%3d%3d  
   Contact id: 2958
  </code></pre>
  
  <p>Then I try to lookup the contact based upon the lookup key using the following code to get the contact id:</p>
  
  <pre><code>Uri lookupUri = Uri.withAppendedPath(ContactsContract.Contacts.CONTENT_LOOKUP_URI, Uri.encode("850i%2bw7vj56otre6eqa9b9t7wa%3d%3d"));
  Uri res = ContactsContract.Contacts.lookupContact(context.getContentResolver(), lookupUri);
  </code></pre>
  
  <p>After doing this "res" is null even though I know the id is valid as it's come from the contact picker.</p>
  
  <p>Putting in some logging the res uri in the lookup is:</p>
  
  <pre><code>content://com.android.contacts/contacts/lookup/850i%252bw7vj56otre6eqa9b9t7wa%253d%253d
  </code></pre>
  
  <p>Which (once encoded) is what I thought it should be.
  Can anyone spot what I'm doing wrong?</p>
  
  <p>The thing is, it works for most people (myself included) but some people are coming across this.</p>