title: File found using android MediaStore but BitmapFactory unable to decode it with path returned from MediaStore
body: <p>I have searched high and low and not found an answer to my particular question, I hope someone can help.
  I am developing this for Android 9 and above, the code I use for older releases works fine.  </p>
  
  <p>It's quite simple, I have stored an image in the MediaStore, I have found the image in the media store, I return its path, I check the path exists and it does, it also has a correct size and is visible in the android Gallery. So why when I try to open it with </p>
  
  <p>val bitmap2 = BitmapFactory.decodeFile(fullPath)</p>
  
  <p>bitmap2 comes back as null - no errors are generated by the above command. The parseAllImages function was taken from the web and tweaked slightly but seems to work ok as far as I can tell.</p>
  
  <p>sample code </p>
  
  <pre><code>        private fun setPic() {
          if (mediaPath.isNotEmpty()) {
              if (Build.VERSION.SDK_INT &gt;= Build.VERSION_CODES.Q) {
                  val content = GalleryAdd.parseAllImages(requireActivity(), mediaPath)
                  val fullPath = content
                  if (File(fullPath).exists()) {
                      val tester = File(fullPath).length()
                      val bitmap2 = BitmapFactory.decodeFile(fullPath)
                      viewModel.setBitmap(bitmap2)
                  }
  
              }
          }
      }
  
      fun parseAllImages(act : Activity, name : String) : String {
          try {
              val projection =
                  arrayOf(MediaStore.Images.Media.DATA, MediaStore.Images.Media._ID)
              val cursor = act.contentResolver.query(
                  MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
                  projection,  // Which columns to return
                  null,  // Return all rows
                  null,
                  null
              )
              val size: Int = cursor!!.getCount()
              /*******  If size is 0, there are no images on the SD Card.  */
              if (size == 0) {
              } else {
                  val thumbID = 0
                  if (cursor != null) {
                      while (cursor.moveToNext()) {
                          val file_ColumnIndex: Int =
                              cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA)
                          /**************** Captured image details  */
                          /*****  Used to show image on view in LoadImagesFromSDCard class  */
                          val idColumn = cursor.getColumnIndexOrThrow(MediaStore.Images.Media._ID)
                          val path: String = cursor.getString(file_ColumnIndex)
                          val fileName =
                              path.substring(path.lastIndexOf("/") + 1, path.length)
                          if (fileName == name)
                          {
                              return path
                          }
                      }
                  }
              }
          } catch (e: Exception) {
              e.printStackTrace()
          }
          return ""
      }
  </code></pre>
  
  <p>Code snippet I use to write to the media store</p>
  
  <pre><code>        if (Build.VERSION.SDK_INT &gt;= Build.VERSION_CODES.Q) {
              val resolver: ContentResolver = activity.contentResolver
              val contentValues = ContentValues()
              contentValues.put(
                  MediaStore.MediaColumns.DISPLAY_NAME,
                  fileName
              )
              contentValues.put(MediaStore.MediaColumns.MIME_TYPE, "image/jpg")
              contentValues.put(
                  MediaStore.MediaColumns.RELATIVE_PATH,
                  Environment.DIRECTORY_PICTURES + File.separator + "fishy"
              )
              val imageUri: Uri? =
                  resolver.insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, contentValues)
  
              val tester = imageUri.toString() + File.separator +  Environment.DIRECTORY_PICTURES + File.separator + "fishy" + File.separator + fileName
              scanLoc = fileName
              fos = resolver.openOutputStream(imageUri!!)!!
  
          val file = File(currentPhotoPath)
          val ins: InputStream = file.inputStream()
          ins.copyTo(fos)
  }
  </code></pre>
  
  <p>Any help or can someone point me to sample code that can read a jpg image from the mediastore given it's name? It's not production ready so please forgive lack of error checks.</p>
  
  <p>Thanks</p>
  
  <p>Lee.</p>