title: BitmapFactory decodeFile returning null
body: <p>I am trying to take a photo using camera and then trying to save to gallery and decode the stream using BitmapFactory but it returns null and also photo taken is not saved to gallery.</p>
  
  <p>So two things here i noticed is photo taken is not getting saved to GALLERY and decodeFile retuning false.</p>
  
  <p>I have tried using BitmapFactory.decodeStream and also tried getting from Uri but nothing worked.</p>
  
  <p>Here is my code:</p>
  
  <p><strong>Take Photo:</strong></p>
  
  <pre><code> if (ActivityCompat.checkSelfPermission(context!!, Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED &amp;&amp; ActivityCompat.checkSelfPermission(context!!, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED)
       ActivityCompat.requestPermissions(activity!!, arrayOf(Manifest.permission.CAMERA, Manifest.permission.WRITE_EXTERNAL_STORAGE), photoWithCamera)
   else
       displayCamera()
  </code></pre>
  
  <p><strong>Camera Display:</strong></p>
  
  <pre><code>private fun displayCamera() {
  Intent(MediaStore.ACTION_IMAGE_CAPTURE).also { takePictureIntent -&gt;
       // Ensure that there's a camera activity to handle the intent
       takePictureIntent.resolveActivity(context!!.packageManager)?.also {
       // Create the File where the photo should go
          createImageFile()?.also {
             uri = FileProvider.getUriForFile(context!!,"com.app.android.sample.fileprovider",it)
             startActivityForResult(takePictureIntent, photoWithCamera)
          }
        }
     }
  }
  </code></pre>
  
  <pre><code>private fun createImageFile(): File? = try {
          File.createTempFile("test", ".png",context?.getExternalFilesDir(DIRECTORY_PICTURES)).apply {
              newPicturePath = absolutePath
          }
      } catch (e: Exception) {
          e.printStackTrace()
          null
      }
  </code></pre>
  
  <pre><code>override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
          super.onActivityResult(requestCode, resultCode, data)
  
          if (resultCode == Activity.RESULT_OK &amp;&amp; data != null &amp;&amp; (requestCode == photoWithCamera){
              when (requestCode) {
                  photoWithCamera -&gt; {
                      galleryAddPic()
                      setPic()
                  }
              }
          }
      }
  </code></pre>
  
  <p><strong>Decode Stream and Set pic (Not Working):</strong></p>
  
  <pre><code>private fun setPic() {
        // Get the dimensions of the View
        val targetW: Int = headingImg.width
        val targetH: Int = headingImg.height
  
        val bmOptions = BitmapFactory.Options().apply {
           // Get the dimensions of the bitmap
           inJustDecodeBounds = true
  
           val photoW: Int = outWidth
           val photoH: Int = outHeight
  
           // Determine how much to scale down the image
           val scaleFactor: Int = min(photoW / targetW, photoH / targetH)
  
           // Decode the image file into a Bitmap sized to fill the View
           inJustDecodeBounds = false
           inSampleSize = scaleFactor
           inPurgeable = true
       }
      //decodeFile returns null here
       BitmapFactory.decodeFile(newPicturePath, bmOptions)?.also { bitmap -&gt;
           headingImg.setImageBitmap(bitmap)
       }
   }
  </code></pre>
  
  <p><strong>Adding photo taken to gallery(Not working):</strong></p>
  
  <pre><code>private fun galleryAddPic() {
       Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE).also { mediaScanIntent -&gt;
           val f = File(newPicturePath)
           mediaScanIntent.data = Uri.fromFile(f)
           context!!.sendBroadcast(mediaScanIntent)
       }
   }
  </code></pre>
  
  <p><strong>Android Manifest:</strong></p>
  
  <pre><code>&lt;uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"
          android:permissionGroup="android.permission-group.STORAGE" /&gt;
  &lt;uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /&gt;
  &lt;uses-permission android:name="android.permission.CAMERA" /&gt;
  
  &lt;provider
     android:name="androidx.core.content.FileProvider"
     android:authorities="${applicationId}.fileprovider"
     android:exported="false"
     android:grantUriPermissions="true"&gt;
     &lt;meta-data
           android:name="android.support.FILE_PROVIDER_PATHS"
           android:resource="@xml/provider_paths"/&gt;
   &lt;/provider&gt;
  </code></pre>
  
  <p><strong>Provider Paths:</strong></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;paths&gt;
    &lt;external-path name="external_files" path="."/&gt;
  &lt;/paths&gt;
  </code></pre>
  
  <p>The file created using createImageFile() is returning file as below:
  /storage/emulated/0/Android/data/com.app.android.sample/files/Pictures/test4153865961621152704.png and I could see the file in the same location</p>
  
  <p>Thanks,
  Sindhu</p>