I'm saving the image captured by the user in the app specific external directory with getExternalFilesDir() and want this image to be also visible in gallery to the user. As per the docs any media (image in my case) saved in these directory is not directly visible to MediaScanner, but we can still make them explicitly visible to MediaScanner using MediaScannerConnection.scanFile().
I am following the same steps as mentioned above, after I save the image in directory I explicitly call MediaScannerConnection.scanFile() but still nothing happens, image is stored in app specific external directory but not visible in gallery?
//getting app specific external directory
val mediaStorageDir = File(app.getExternalFilesDir(Environment.DIRECTORY_PICTURES))
val file = File("${mediaStorageDir.path}${File.separator}front_image.jpg")
//saving file
val bos = FileOutputStream(file)
val original = BitmapFactory.decodeByteArray(this, 0, size)
original.compress(Bitmap.CompressFormat.JPEG, 100, bos)
//after saving file
MediaScannerConnection.scanFile(context, arrayOf(file.absolutePath), null, null)
I am testing on Android Version: 9 | Custom OS: Funtouch OS_9.2 | Model: vivo 1921
Yes getExternalFilesDir() is an app specific directory. The MediaStore scanner will not index it and hence Gallery apps are unaware of your images. Thats how it is intended to be. –