Force Gallery app refresh on Android 4.4

1

I have an application that manipulates images, it has options to move and delete images, when deleting an image is sent a boradcast so that the android gallery application recognizes that the image is no longer there. It works perfectly, except Android 4.4!

I'm using 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 already researched and tried scanFile, but it does not work, the Android 4.4 Gallery app does not recognize the change

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

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

    
asked by anonymous 31.10.2014 / 04:44

1 answer

1

I found the answer, it was my lack of attention. the media scan does not accept a folder as path, it has to be by image per image in a String vector, to only use scanFile.

wherever you go through the folder:

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

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

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

    
31.10.2014 / 06:04