I have saved a video in getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS)
path in the android private directory. I want to show the video file in the gallery. I have tried MediascannerConnection.scanFile but it did not work.
Is there any altermative?
Question posted in Android Studio
The official documentation can be found here.
The official documentation can be found here.
3
Answers
is a private location for your app.
The MediaStore will not scan files from that location.
And hence no Gallery app will know about them as Gallery apps query the MediaStore.
you have to save your file in shared storage, for example, if u want to save pics, save them in /pictures folder or videos save them in videos folder
P.s, this issue rises in scoped storage only, i.e sdk > 28 so start using scoped storage
Give this a read (Storage changes in android 11)
You can use the MediaStore api to load a video from the gallery.
This code is for loading all videos from the downloads collection, if you want a specific one you can change the value of the
selection
variable to match only the specific video.After retrieving the desired content uri, you can load the video thumbnail into an
ImageView
using Glide:Or just use a
VideoView
and set the content uri as the video uri to play the video.