title: Contact Photo not being found?
body: <p>I have been searching throughout Stackoverflow and the Android official documentation about retrieving the photos of Contacts, and I just don't understand it at all. I am pretty new to Java, so I don't even understand what an InputStream does or what a URI is, besides a &quot;Uniform Resource Identifier.&quot;</p>
  <p>Because of this, I just copy and pasted the code from the Android documentation because I figured there was no way to go wrong with it. Well it turns out, every single time I try to open a photo, it returns null. Google sure did make going about the contacts pretty dang hard. Like there is so much to simply retrieving a contact's name, let alone the picture.</p>
  <p>Here is the code:</p>
  <p><code>openPhoto()</code> function:</p>
  <pre><code>private InputStream openPhoto(long contactId) {
      Uri contactUri = ContentUris.withAppendedId(ContactsContract.Contacts.CONTENT_URI, contactId);
      Uri photoUri = Uri.withAppendedPath(contactUri, ContactsContract.Contacts.Photo.CONTENT_DIRECTORY);
  
      Cursor cursor = getContentResolver().query(photoUri,
              new String[] {ContactsContract.Contacts.Photo.PHOTO}, null, null, null);
  
      if(cursor == null) {
          return null;
      }
  
      try {
          if(cursor.moveToFirst()) {
              byte[] data = cursor.getBlob(0);
  
              if(data != null)
                  return new ByteArrayInputStream(data);
          }
      } finally {
          cursor.close();
      }
  
      return null;
  }
  </code></pre>
  <p>Area where photo is opened:</p>
  <pre><code>...
  InputStream stream = openPhoto(c.getID());
  if(stream != null)
      Log.i(&quot;PHOTO&quot;, stream.toString());
  else
      Log.i(&quot;NULL&quot;, &quot;PHOTO IS NULL&quot;);
  ...
  </code></pre>
  <p>In the code above, the Logger always keeps logging &quot;NULL&quot; : &quot;PHOTO IS NULL&quot;. So, <strong>Why is the photo of a contact not being found here?</strong></p>
  <p><strong>EDIT</strong>: if you have an answer, please explain what is going on. I appreciate any answer, but I would like to learn what is going on. So far, this is still unsolved. So if you have an answer, just explain why. Thank you.</p>