title: MediaStore.Images get full image from thumb Uri /id
body: <p>There are a couple of solutions on how to get thumbnail from the full image, such as<br>
  <a href="https://stackoverflow.com/questions/8383377/android-get-thumbnail-of-image-stored-on-sdcard-whose-path-is-known">android get thumbnail of image stored on sdcard whose path is known</a>  </p>
  
  <p>However, <strong>I need on the contrary to receive full image Uri from a Thumbnail Uri (or thumbnail id)</strong>.<br>
  Here is how I get thumbnails:</p>
  
  <pre><code>fun getGalleryImages(): List&lt;LocalImage&gt; {
      val baseUri: Uri = MediaStore.Images.Thumbnails.EXTERNAL_CONTENT_URI
      val listOfAllImages = ArrayList&lt;LocalImage&gt;()
      // Set up an array of the Thumbnail Image ID column we want
      val projection = arrayOf(MediaStore.Images.Thumbnails._ID, MediaStore.Images.Thumbnails.IMAGE_ID)
      // Create the cursor pointing to the SDCard
      val cursor = context.contentResolver.query(
              baseUri,
              projection,
              null, 
              null,
              null)
  
      // Get the column index of the Thumbnails Image ID
      val thumbColumnIndex = cursor.getColumnIndexOrThrow(MediaStore.Images.Thumbnails._ID)
      val fullColumnIndex = cursor.getColumnIndexOrThrow(MediaStore.Images.Thumbnails.IMAGE_ID)
  
      var thumbnailUri: Uri?
      while (cursor.moveToNext()) {
          val thumbId = cursor.getString(thumbColumnIndex)
          thumbnailUri = Uri.withAppendedPath(MediaStore.Images.Thumbnails.EXTERNAL_CONTENT_URI, "" + thumbId)
          // here I save image id for later retrieving full image
          val imageId = cursor.getString(fullColumnIndex)
          listOfAllImages.add(LocalImage(thumbnailUri = thumbnailUri), imId = imageId)
      }
      cursor.close()
      return listOfAllImages
  }
  </code></pre>
  
  <p>And then I have to retrieve a full image by image id (or by thumbnail Uri)</p>
  
  <pre><code> private fun getFullImage(imageId: String): Uri {
      val projection = arrayOf(MediaStore.Images.Media._ID, MediaStore.Images.Media.DATA)
  
      val cursor = context.contentResolver.query(
              MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
              projection,
              MediaStore.Images.Media._ID + "=?",
              arrayOf(imageId),
              null)
      val columnIndex = cursor.getColumnIndex(projection[0])
      if (cursor.moveToFirst()) {
          return Uri.withAppendedPath(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, "" + cursor.getString(1))
      }
      cursor.close()
      return Uri.EMPTY
  }
  </code></pre>
  
  <p>This returns me a Uri which looks realistic:</p>
  
  <pre><code>content://media/external/images/media//storage/emulated/0/DCIM/Camera/IMG_20170720_085045.jpg   
  </code></pre>
  
  <p>However, the Uri seems to be invalid since I cannot retrieve the image from it:</p>
  
  <pre><code>val bitmap = MediaStore.Images.Media.getBitmap(activity.contentResolver, image.imageUri)
  </code></pre>
  
  <p>java.lang.IllegalStateException: Unknown URL: content://media/external/images/media//storage/emulated/0/DCIM/Camera/IMG_20170720_085045.jpg
                                                                                         at android.os.Parcel.readException(Parcel.java:1950)
                                                                                         at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:183)
                                                                                         at android.database.DatabaseUtils.readExceptionWithFileNotFoundExceptionFromParcel(DatabaseUtils.java:146)
                                                                                         at android.content.ContentProviderProxy.openTypedAssetFile(ContentProviderNative.java:698)</p>
  
  <p>Picasso also fails to load image from this Uri </p>