react-native-fs icon indicating copy to clipboard operation
react-native-fs copied to clipboard

Android: Media Scanner

Open paulondc opened this issue 9 years ago • 14 comments

Hi,

I noticed that when new images (or any file) are created under a location aka PicturesDirectoryPath they don't become visible immediately under the gallery app. The reason for that seems it requires an extra step to tell the android's mediascanner about the new files. By not doing that means the new files are going to get "visible" for users only when mediascanner starts which happens during the boot.

Following bellow a stackoverflow about this issue: http://stackoverflow.com/questions/9414955/trigger-mediascanner-on-specific-path-folder-how-to

Cheers

paulondc avatar Apr 19 '16 07:04 paulondc

@paulondc Is there anything we can do here?

johanneslumpe avatar Apr 24 '16 07:04 johanneslumpe

Hi @johanneslumpe,

I believe by having a way to trigger the mediascanner through native-fs would be beneficial for the library, I can see this feature being useful for any application that create files under shared places which are meant to be shared across different apps (like pictures), therefore this feature would be in line with the library, since this just makes the files generated by them available in android's mediastore:

I was thinking something like:

  @ReactMethod
  public void updateMediaStore(String path, Callback callback) {
    ...
  }

What do you think about it ?

paulondc avatar Apr 24 '16 09:04 paulondc

@paulondc I'm not sure that this really belongs into the library. I'd kind of like to open this one up for discussion and see if other people think it's useful before we make a decision on this.

johanneslumpe avatar Apr 25 '16 08:04 johanneslumpe

+1 this is very useful for me. I cannot see downloaded image at Gallery unless restart the device

pewh avatar May 14 '16 10:05 pewh

+1

havir avatar Jun 19 '16 08:06 havir

When I used Android File Transfer to check the files on Android, and the folder wasn't there after mkdirs, due to this reason. It's necessary to show the folder to user, somehow, they can download their assets directly there, or the app will be complex to have function to be the same for them.

If the folder or file changes can be shown after it created, or even after the device reboot, will be good, looks like it can't for now.

Anyway, to build a native module by adding MTP scan API out of this lib is also possible, but if this lib can provide this as separate API sets, will be very helpful.

I believe this problem also happened in deleting a file, for example Image, then we can't see this change in system gallery or else.

hellomaya avatar Jul 24 '17 09:07 hellomaya

+1

phillmill avatar Jun 11 '18 22:06 phillmill

This is still an issue. This library needs scanFile function like rnfetchblob https://github.com/wkh237/react-native-fetch-blob/wiki/File-System-Access-API#scanfilepathstringpromise-android-only. I currently need to use both libraries only for this function. PR #155 Added this function but it was closed.

lefoy avatar Aug 20 '18 19:08 lefoy

Hm... seems that we should reactivate this mentioned PR, @lefoy Do you want to do another PR with that?

itinance avatar Aug 20 '18 19:08 itinance

PR #544 should solve this issue. Using this method I can save images to my gallery and see them immediately. Thank you for your quick reply @itinance .

lefoy avatar Aug 20 '18 19:08 lefoy

@itinance can you please merge my PR?

lefoy avatar Sep 04 '18 15:09 lefoy

Please please @itinance merge @lefoy PR. I also need to have rn-fetch-blob installed to only use scanFile.

Fsarmento avatar Oct 17 '18 10:10 Fsarmento

Merged. Sorry for being late, didn't get a notice on this PR. I came across this one while reading thru recent pull request. Please upgrade to v2.13.

itinance avatar Dec 19 '18 13:12 itinance

If you have saved the file, but it doesn't appear in the gallery, just add scanFile after success

RNFS.copyFile(imageUrl, newPath)
      .then(() => {
        RNFS.scanFile(RNFS.PicturesDirectoryPath); // add this
      })
      .catch(err => {
        const message = err?.message;
      });

it works for me, and the image immediately appears in the gallery

imamrobani avatar Sep 08 '23 09:09 imamrobani