3

In my application, I have downloaded a video from the web and save it in the device's Internal storage. I can see the video file in the folder where I stored the video using the File Explorer app. But the gallery app in my mobile doesn't list the video from saved from my app. The gallery app lists the video I have downloaded from other apps like WhatsApp. What is the reason?

To see the video saved from my application in the gallery app, whether I need to set any permission in my app?

Madhan
  • 133
  • 2
  • 9
  • You better look for the answer at the sister site http://stackexchange.com/ – gauravsheohar Feb 05 '16 at 04:52
  • You have to send signal to your Gallery to notify you have added a file. You can see multiple answers under this questions: http://stackoverflow.com/questions/2170214/image-saved-to-sdcard-doesnt-appear-in-androids-gallery-app – Sharjeel Feb 05 '16 at 04:57

1 Answers1

5

Just add below line after you save the video file -

For api < 14

sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED, Uri.parse("file://" + 
Environment.getExternalStorageDirectory())));

for api >= 14

MediaScannerConnection.scanFile(MainActivity.this, 
new String[] { Environment.getExternalStorageDirectory().toString() }, 
null, 
new MediaScannerConnection.OnScanCompletedListener() {

    public void onScanCompleted(String path, Uri uri) {

              Log.i("ExternalStorage", "Scanned " + path + ":");
              Log.i("ExternalStorage", "-> uri=" + uri);
    }
});
kevz
  • 2,727
  • 14
  • 39
  • @Madhan: Most Welcome :) – kevz Feb 18 '16 at 12:46
  • its not working for downloaded videos in removable sdcard package directory :( – Hamid Zandi Sep 17 '18 at 08:47
  • @do01: try replacing "Environment.getExternalStorageDirectory()" with the path where the video is stored. – kevz Sep 17 '18 at 11:29
  • removable sdcard dir is like: /storage/1825-374/Android/data/com.example/files/my_video.mp4 and this is not shown in gallery at all :( – Hamid Zandi Sep 17 '18 at 12:43
  • @do01: try "/storage/1825-374/Android/data/com.example/files/" instead of "Environment.getExternalStorageDirectory()". – kevz Sep 18 '18 at 05:56
  • @kevz : It not working, videos in app package directory cant be introduced to gallery! and we cant save videos in other directory of removable sdcard due to new android security rules – Hamid Zandi Sep 18 '18 at 06:06