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)