Android的文件删除叶画廊空占位符 [英] Android file delete leaves empty placeholder in Gallery

查看:167
本文介绍了Android的文件删除叶画廊空占位符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我通过插入图像:

    ContentValues values = new ContentValues();   
    values.put(Images.Media.TITLE, filename);
    values.put(Images.Media.DATE_ADDED, System.currentTimeMillis()); 
    values.put(Images.Media.MIME_TYPE, "image/jpeg");

    Uri uri = this.getContentResolver().insert(Images.Media.EXTERNAL_CONTENT_URI, values);

但是,当我试图删除

But when I try to delete

    File f = new File(imageURI);
    f.delete();

图片不再存在,但空的占位符。任何想法?

The picture is no longer there but an empty placeholder is. Any ideas?

推荐答案

Android有各种各样的缓存,它跟踪的媒体文件。

Android has a cache of sorts that keeps track of media files.

试试这个:

sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED, Uri.parse("file://" + Environment.getExternalStorageDirectory())));

这使得MediaScanner服务运行一次,这应该从设备的缓存中删除的删除的图像。

It makes the MediaScanner service run again, which should remove the deleted image from the device's cache.

看来你还需要这个权限添加到您的Andr​​oidManifest.xml:

Looks like you also need to add this permission to your AndroidManifest.xml:

<intent-filter>
  <action android:name="android.intent.action.MEDIA_MOUNTED" />
  <data android:scheme="file" /> 
</intent-filter>

这篇关于Android的文件删除叶画廊空占位符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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