0

I have this function that saves an image to the Internal storage/Android/media folder on your phone:

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
}

I want to change the code so that I can save the image in the default Images folder that way when the user opens their Gallery app, they'll easily be able to see it. How do I do that?

daniel.jbatiz
  • 437
  • 4
  • 18
Bert Hanz
  • 417
  • 1
  • 7
  • 16
  • Saving to Gallery depends on the platform version, 29 (Android 10) introducing some [new ways](https://stackoverflow.com/a/57265702/192373). – Alex Cohn Jul 12 '20 at 07:43
  • @AlexCohn What do I pass in as the parameters? My `getOutputDirectory` doesn't require any parameters but the link you sent me as methods that require parameters. – Bert Hanz Jul 12 '20 at 16:09
  • The main difference is that you cannot simply calculate the full path and use file API to create this file. You need a **ContentResolver** to explicitly register your picture for Gallery. – Alex Cohn Jul 13 '20 at 07:21

0 Answers0