1

I have a small app that when I run it make a folder in my SD then save some Videos inside the folder

The thing is the app does the work and make the folder and save the files and I still can see it in SD using file manager or from my PC when I connect it via USB

But for e.g when I start Whatsup or my Gallery I can't see the folder or the videos !

I still can see the folder and videos that stored in the SD using File Manager

so what's wrong ? why I can't see the folder and videos in the Gallery or other programs when I want to attach the video ..

I used the same code link for my App to create the folder and check :

File folder = new File(Environment.getExternalStorageDirectory() + "/TollCulator");
boolean success = true;
if (!folder.exists()) {
    success = folder.mkdir();
}
if (success) {
    // Do something on success
} else {
    // Do something else on failure 
}
Community
  • 1
  • 1
boudi
  • 682
  • 1
  • 8
  • 19

2 Answers2

2

The Gallery works off of MediaStore, and WhatsApp may as well. Use MediaScannerConnection and its scanFile() static method to arrange to have your file(s) be indexed and available through the MediaStore, and see if that helps.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • works thanks ! Question : should I use the MediaScannerConnection at the beginning of the activity when it run or keep it after my function and things are loaded? what's the right way – boudi Sep 17 '14 at 12:19
  • 1
    @boudi: You need to wait until the file is written with the desired contents. – CommonsWare Sep 17 '14 at 12:38
2
You need to Tell the media scanner about the new file so that it is immediately available to the user. 

For example

MediaScannerConnection.scanFile(this,
            new String[] { file.toString() }, null,
            new MediaScannerConnection.OnScanCompletedListener() {
        public void onScanCompleted(String path, Uri uri) {
            Log.i("ExternalStorage", "Scanned " + path + ":");
            Log.i("ExternalStorage", "-> uri=" + uri);
        }
    });
Alex Chengalan
  • 8,211
  • 4
  • 42
  • 56