title: Android Q Kotlin - API 29: check if image exists
body: <p>This is the code I'm using to save image in Android Q:</p>
  
  <pre><code>private var fileName = ""
  private fun downloadImage(){
      val folderName = "Funny"
      fileName = "bla_" + dlImageURL.split("/").toTypedArray().last()
  
      // find out here if this image already exists
  
      val requestOptions = RequestOptions()
          .skipMemoryCache(true)
          .diskCacheStrategy(DiskCacheStrategy.NONE)
  
  
      val bitmap = Glide.with(this@DownloadImage)
          .asBitmap()
          .load(dlImageURL)
          .apply(requestOptions)
          .submit()
          .get()
  
  
  
      try {
  
          val values = ContentValues()
          values.put(MediaStore.Images.Media.MIME_TYPE, "image/jpeg")
          values.put(MediaStore.Images.Media.DATE_ADDED, System.currentTimeMillis() / 1000)
          values.put(MediaStore.Images.Media.RELATIVE_PATH, "Pictures/$folderName")
          values.put(MediaStore.Images.Media.IS_PENDING, true)
          values.put(MediaStore.Images.Media.DATE_TAKEN, System.currentTimeMillis())
          values.put(MediaStore.Images.Media.DISPLAY_NAME, fileName)
          values.put(MediaStore.Images.Media.TITLE, fileName)
          // RELATIVE_PATH and IS_PENDING are introduced in API 29.
  
          val uri: Uri? = this@DownloadImage.contentResolver.insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values)
  
          if (uri != null) {
              saveImageToStream(bitmap, this@DownloadImage.contentResolver.openOutputStream(uri))
              values.put(MediaStore.Images.Media.IS_PENDING, false)
              this@DownloadImage.contentResolver.update(uri, values, null, null)
          }
  
      } catch (e: Exception) {
  
      }
  }
  
  
  
  private fun saveImageToStream(bitmap: Bitmap, outputStream: OutputStream?) {
      if (outputStream != null) {
          try {
              bitmap.compress(Bitmap.CompressFormat.JPEG, 95, outputStream)
              outputStream.close()
          } catch (e: Exception) {
              e.printStackTrace()
          }
      }
  } 
  </code></pre>
  
  <p>How can I find out if this image already exists in the gallery before I download it? I commented where it needs to be.</p>
  
  <p>I already looked up and can't find out how to get the damn path, it was much easier &lt; API 29</p>