Skip to content Skip to sidebar Skip to footer

Android - Why My Saved Image Is Not Appearing In The Default Gallery Of My Phone?

I am trying to save an image from my application to the default gallery of my phone. The code below works perfectly if I have a SD card on the phone. The image saved appears in the

Solution 1:

Another easy way to do it. Add this after saving your file.

File imageFile = ...
MediaScannerConnection.scanFile(this, newString[] { imageFile.getPath() }, newString[] { "image/jpeg" }, null);

Solution 2:

I haven't tried this, but I believe you need to run the Media Scanner to scan the internal storage directory so that the gallery can see your newly saved image. Check this post here.

Solution 3:

Copy Past this Function in your Activity

privatevoidscanner(String path) {

        MediaScannerConnection.scanFile(FrameActivity.this,
                newString[] { path }, null,
                newMediaScannerConnection.OnScanCompletedListener() {

                    publicvoidonScanCompleted(String path, Uri uri) {
                        Log.i("TAG", "Finished scanning " + path);
                    }
                });
    }

And then add this Line where you save your image

scanner(imageFile.getAbsolutePath());

Solution 4:

Try this.

Write down this line once image stored in gallery.

Filefile= ..... // Save file

context.sendBroadcast(newIntent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, Uri.fromFile(file)));

Solution 5:

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {

                sendBroadcast(newIntent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE,
                        Uri.parse("file://"
                                + Environment.getExternalStorageDirectory())));
            } else {
                sendBroadcast(newIntent(Intent.ACTION_MEDIA_MOUNTED,
                        Uri.parse("file://"
                                + Environment.getExternalStorageDirectory())));
            }

Post a Comment for "Android - Why My Saved Image Is Not Appearing In The Default Gallery Of My Phone?"