1

How should I notify images Content Provider, that I just saved a file in Pictures directory? I expect e.g. Gallery-like apps to be able to see my new file.

Uri uri = Uri.fromFile(file);
getContext().getContentResolver().notifyChange(uri, null);

which I found somewhere (Vogella?) does not seem to work. Or is it a wrong approach from the start?

Antek
  • 721
  • 1
  • 4
  • 27

1 Answers1

3

The image notification is done after the image is inserted into media database. This is usually done by the android system media scanner when it finds the image.

You can write your own code to insert the image into the media database and then call getContext().getContentResolver().notifyChange(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, null); to notify that some image has changed without beeing specific exatly which image.

If you modified an image that is already in the media database you have to translate the file uri into a content: uri. getContext().getContentResolver().notifyChange(imageContentUri, null); .

If you are implementing for android-4.4 or later You can ask the media scanner to (re)analyse your file. For details see How to trigger MediaScan on Nexus 7? . in pre android-4.4 this might not work as expected (i.e. on my android-4.2 it starts a complete rescan)

k3b
  • 14,517
  • 7
  • 53
  • 85
  • hmm, triggering MediaScan would be preferred - because of amount of code needed. Unfortunately, it causes the file to appear in gallery, but its content is not visible. I'll check the other method as well – Antek Jul 27 '17 at 12:53