androidandroid-galleryandroid-mediascanner

Android add images from OBB directory to Gallery


I am trying to scan images which are stored in the OBB directory to the Gallery (in this case Google Photos).

If I scan from the Pictures Folder everything works fine.

Working code:

String outputDir = String.format("%s/%s", Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES),"Pictures");

OBB directory code:

String outputDir = String.format("%s/%s", context.getObbDir(),"Pictures");

For scanning:

MediaScannerConnection.scanFile(context,
                new String[] { picture.getUrl() }, null,
                new MediaScannerConnection.OnScanCompletedListener() {
                    public void onScanCompleted(String path, Uri uri) {
                        System.out.print("Scanned " + path);
                    }
                });

picture.getUrl() is in this case the file url. It is stored in a data object first and then sent to the scanner.


Solution

  • I added my comment as answer so the question can be marked as answerd.

    If the the picture folder or one of it-s parent folders contain a ".nomedia" file the media scanner will not index the image(s)