0

I am downloading file from my server. Due to Environment.getExternalStorageDirectory() is deprecated To improve user privacy, direct access to shared/external storage devices I am saving the video file to the app folder (Android/data/com.myapp/Videos) using getExternalFilesDir.

What I need is this folder (Videos) will be visible in the gallery, or the file will be visible, either way. But my code does not seem to work:

    val mainPath = requireActivity().getExternalFilesDir(null)!!.path + "/"
    val path = "$mainPath/Videos/clip1.mp4"

    val values = ContentValues(3)
    values.put(MediaStore.Video.Media.TITLE, "My video title")
    values.put(MediaStore.Video.Media.MIME_TYPE, "video/mp4")
    values.put(MediaStore.Video.Media.RELATIVE_PATH, path)
    
    requireActivity().contentResolver.insert(MediaStore.Video.Media.EXTERNAL_CONTENT_URI, values)
Dim
  • 4,527
  • 15
  • 80
  • 139
  • For what are you using that .insert() uri? It has nothing to do with saving files to getExternalFilesDir(). What are you doing? – blackapps Sep 19 '21 at 14:13
  • The file is already located in the path. I just need it to be visible in the gallery. – Dim Sep 19 '21 at 14:16
  • 1
    These may help: https://stackoverflow.com/a/57649669/3466808, https://stackoverflow.com/a/62879112/3466808. – Sam Chen Sep 19 '21 at 14:45

1 Answers1

-3

Files in getExternalFilesDir() will not be scanned by the media store.

And hence will not be shown by Gallery apps.

blackapps
  • 8,011
  • 2
  • 11
  • 25