Nguyen Tien Dung
Nguyen Tien Dung

Reputation: 638

When do we need to use FileProvider?

I'm quite confused about when to use FileProvider when we can save a bitmap to file like this

fun saveBitmapToFile(bitmap: Bitmap) {
   val fileName = generaUniqueName()
   val subdirectory = File(application!!.filesDir, Constants.IMAGE_DIRECTORY)
   if (!subdirectory.exists()) {
        subdirectory.mkdirs()
   }
   val imageFile = File(subdirectory, fileName)
   val outputStream = FileOutputStream(imageFile)
   bitmap.compress(Bitmap.CompressFormat.JPEG, 100, outputStream)
   outputStream.flush()
   outputStream.close()
}

So, is it only necessary when the file we save needs to be accessed from external applications? Or is there something else that makes it important?

Upvotes: 0

Views: 68

Answers (1)

CommonsWare
CommonsWare

Reputation: 1007474

is it only necessary when the file we save needs to be accessed from external applications?

Generally yes. For files that your app uses internally, you normally do not need FileProvider.

Upvotes: 1

Related Questions