-1

So I hope the title makes sense but heres more context .

I want to make my own camera app and I am following this Google Practice for cameraX. I have got the camera working on my physical phone but the problem is I cant view my images that I have taken. Weird thing is the images appear in the gallery the next day and not right after taking a photo.

Now im not too sure why that is but after researching it seems that the file is not being saved in a public directory at least thats the conclusion I have succumbed to. This is the directory that the app saves to: /storage/emulated/0/Android/media/com.astro.openingcamera/openingCamera.

This is the block of code that produces the directory

    private fun getOutputDirectory(): File {
    val mediaDir = externalMediaDirs.firstOrNull()?.let {
        File(it, resources.getString(R.string.app_name)).apply { mkdirs() } }
    return if (mediaDir != null && mediaDir.exists())
        mediaDir else filesDir
}

So is there a away to modify this block so that it allows me to view the images right after taking the photo ? cause keep in mind the images dont appear in the gallery right after taking the photo.

Others have pointed to this documentation but I dont really understand it

Thanks in advance

  • 1
    Which Android version runs on used device? Further you shouls start the mediascanner for your new file. Then it gets indexed and you see it in the gallery right away. – blackapps Apr 28 '21 at 08:44
  • I think im using API 29 or 30. I havent heard of media scanner so ill look into that – Crimson Space Apr 28 '21 at 18:54

1 Answers1

0

I found the solution as suggested by blackapps I used a mediascanner to update the directory so heres my code

 MediaScannerConnection.scanFile(this ,
            arrayOf(outputDirectory.toString()),null,
    null)