删除的图片仍在图库中可见 [英] Deleted picture still visible in gallery

查看:131
本文介绍了删除的图片仍在图库中可见的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在这里有个小问题.

在我的应用程序中,我让用户从图库中选择图片.在执行其他任何操作之前,我先保存路径. 当用户选择他想要的图片时,我希望将其复制到另一个文件夹中,然后从原始文件夹中删除.

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.

好吧,kiiinda起作用了.原始图片被删除,并且副本出现在另一个文件夹中. Buuut.它仍然在那里. 在画廊中仍然可以看到已删除的图片,也看不到副本.当我调用Gdx.files.absolute(originalPath).exists()时,它返回false,而Gdx.files.external(copyPath).exists()时它返回true,我可以使用图片的副本没有问题.

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.

图库似乎没有更新.

我用它来删除和复制图片:

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是图库中原始图片的绝对路径,并且fileName是文件名("picture.jpg")

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.

我也有WRITE_EXTERNAL_STORAGE权限.

Also, I do have the WRITE_EXTERNAL_STORAGE permission.

你们知道怎么了吗?

推荐答案

找到了解决方案.

我必须使用此功能更新图库:

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))));
}

这篇关于删除的图片仍在图库中可见的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆