Force refresh Gallery app on Android 4.4

Asked

Viewed 53 times

1

I have an application that handles images, in it has options to move and delete images, when I delete an image is sent a boradcast so that the android gallery application recognize that the image is no longer there. Is working perfectly, except for Android 4.4!

I’m wearing it like this:

public void forceMediaScan(String path){
        File f1 = new File(path);
        Intent scanIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
        scanIntent.setData(Uri.fromFile(f1));
        getActivity().sendBroadcast(scanIntent);
}

I’ve searched and tried to use scanFile, but it doesn’t work, the Gallery application of Android 4.4 does not recognize the change

MediaScannerConnection.scanFile(getActivity(), new String[]{path}, null,null);

I have tried using scanFile for a specific file and for an entire path (which is the case for the example), but it does not work.

1 answer

1


I found the answer. the media scan does not accept a Folder as path, has to image by image in a String array, only so use scanFile.

inside the path through the folder:

MediaScannerConnection.scanFile(getActivity(), new String[]{aFile.getAbsolutePath()}, null,null);

Note that I used getAbsolutePath() to take the full path.

Do not use sendBoradcast for this purpose! scanFile serves for this, and is much faster in this case.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.