Skip to content Skip to sidebar Skip to footer

Use Mediascannerconnection Scanfile To Scan Downloaded Image File

I am working on an app in which I save image(s) to a directory but the Images wont show up in gallery until I restart the phone. Here's My Code Snippet public class SaveTask extend

Solution 1:

Use

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

//but it only works on API <19

Second Method

privatevoidscanFile(String path) {

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

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

Call it like

scanFile(yourFile.getAbsolutePath());

Also see this Answer

Post a Comment for "Use Mediascannerconnection Scanfile To Scan Downloaded Image File"