title: Accessing contact photo from content uri
body: <p>I am trying to access a number of things from a contact returned from a Contacts ACTION_PICK Intent- name, phone number, and photo. There is no problem with retrieving the name and phone number, but when I try to access the photo I am getting a SecurityException every time, saying the GLOBAL_SEARCH permission is required. Here is the logcat...</p>
  
  <pre><code>Caused by: java.lang.SecurityException: Permission Denial: reading com.android.providers.contacts.ContactsProvider2 uri content://com.android.contacts/contacts/14/photo from pid=4526, uid=10223 requires android.permission.GLOBAL_SEARCH, or grantUriPermission()
  </code></pre>
  
  <p>I've combed stackoverflow and tried every method I've found, and as a sanity check I'm now using the method recommended by google as follows</p>
  
  <pre><code>public InputStream retrieveContactPhoto() {
  
      Uri contactUri = ContentUris.withAppendedId(Contacts.CONTENT_URI, Long.valueOf(mContactID));
      Uri photoUri = Uri.withAppendedPath(contactUri, Contacts.Photo.CONTENT_DIRECTORY);
      Cursor cursor = getContentResolver().query(photoUri,
              new String[] {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>However, I get the same SecurityException in every case. It is thrown at the contentResolver query line. Apparently there's no way to be granted the GLOBAL_READ permission, so I'm not quite sure how to address the problem.
  Also, since I've been able to retrieve the name and phone number with no issue, I can't imagine that there's something wrong with how I'm creating the Intent, but for completeness, here is the startActivityForResult() call</p>
  
  <pre><code>Intent contactIntent = new Intent(Intent.ACTION_PICK, Contacts.CONTENT_URI);
  
  startActivityForResult(contactIntent, INTERVIEWEE_FROM_CONTACTS);
  </code></pre>
  
  <p>I've scoured the internet and can't find a single case of someone receiving this SecurityException, all I ever see are apps that need the READ_CONTACTS and WRITE_CONTACTS permissions, so I'm sure that I'm overlooking something obvious, but I'm just totally stumped. I am testing on a Nexus 6p, running Nougat.
  Please help!</p>