0

I am using Files.copy API (package: java.nio.file) for copying images to new directory. The operation is working fine and I can see files are copied properly in new directory. But those newly copied files are not visible in Gallery by default.

If if use default file manager and try to move those newly copied files again in new folder then that new folder is immediately visible in phone gallery.

Do I need any change here? or I am missing something ?

Code snippet which I am using:

for (Path srcPath : sourcePaths) {
                String fileName = srcPath.getFileName().toString();
                File targetFile = new File(SDCARD_PATH + TARGET_PATH + fileName);


                if (!fileName.equalsIgnoreCase(".nomedia") && !targetFile.exists()) {
                    Files.copy(srcPath, targetFile.toPath(), StandardCopyOption.COPY_ATTRIBUTES);
                }
            }
Cœur
  • 37,241
  • 25
  • 195
  • 267

1 Answers1

0

try to rename files it might work image visibility

  • 1
    Thanks for your suggestion. Let me try that. – Avinash Tingre Apr 07 '21 at 17:09
  • Yes right. When I manually rename files from file manager its displaying images in gallery. But when I rename or create dummy file by using API its not making any difference :( – Avinash Tingre Apr 07 '21 at 17:34
  • Thanks a lot bro. After crawling through your second suggestion I reached to this solution which solved my issue. [Solution](https://stackoverflow.com/a/4158292/12715840). – Avinash Tingre Apr 07 '21 at 17:50
  • yeah i came across scanmedia but it was old post and i though might be dead because google is making so much api deseparation and making new apis – vaimalaviya Apr 07 '21 at 19:31