Deleted picture still visible in gallery

半城伤御伤魂 提交于 2019-12-11 09:37:10

问题


I have a small problem here.

In my application I let the user select a picture from the gallery. I save the path to it before doing anything else. When the user picks the picture he wants, I want it to be copied in a other folder, and then deleted from the original one.

Well, it kiiinda works. The original picture is deleted, and a copy appears in the other folder. Buuut. It's still there. The deleted picture can still be seen in the gallery, and the copy can't be seen. When I call Gdx.files.absolute(originalPath).exists() it returns false, and Gdx.files.external(copyPath).exists() it returns true, and I can work with the copy of the picture with no problem.

It looks like the gallery is not updated.

I use this to delete and copy a picture :

public void MoveToCustomFolder() {
    if (DoesOriginalPathExist()) {
        if (!DoesCopyExist()) {
            System.out.println("Copying");
            Gdx.files.external("/CustomFolder/" + fileName).write(Gdx.files.absolute(filePath).read(), true);
        }
        System.out.println("Deleting");
        Gdx.files.absolute(filePath).delete();
    }
}

filePath being the absolutePath of the original picture in the gallery and fileName the name of the file ("picture.jpg")

I found something during my research. When clear the data of the media storage application, after little time the correct gallery shows up, with no deleted pictures and with copies where they belong.

Also, I do have the WRITE_EXTERNAL_STORAGE permission.

Do you guys know what's wrong ?


回答1:


Found the solution.

I had to update the Gallery with this function :

public void UpdateGallery(String filePath) {
    sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, Uri.fromFile(new File(filePath))));
}


来源:https://stackoverflow.com/questions/26740628/deleted-picture-still-visible-in-gallery

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!