如何删除相册视频? [英] How to delete a video from Gallery?

查看:158
本文介绍了如何删除相册视频?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试着删除我的影片与此code,但在某些设备上他们似乎不能在库中播放的视频损坏

I've tried to delete my videos with this code, but on some devices they appear as damaged videos that can't be played in Gallery.

File videoFile = new File(filepath);
videoFile.delete();

我怎样才能正确地删除它们?

How can I delete them properly?

推荐答案

画廊显示mediastore数据。从您必须删除mediastore数据库行视频画廊彻底删除该文件。

Gallery is displaying mediastore data. To completely delete the file from the gallery you have to delete the mediastore database row for the video.


  • 在code从mediastore删除的记录。

  • In code remove the record from the mediastore.

// delete the mediastore entry;
getContext().getContentResolver().delete(mediaStoreUri, null, null);


现在所有你需要的是mediaStoreUri可以从文件路径得到它。

Now all you need is the mediaStoreUri you can get it from the file path.

//found this on github 

https://gist.github.com/jdeloach/31​​72742

问题与上面的链接PFER他们使用的ContentUris.withAppendedId静态方法来得到URI,而是他们只是添加斜线和字符串我想$ P $它

Problem with above link I would prefer they use the ContentUris.withAppendedId static method to get the Uri but instead they just add a slash and string it out

Uri mediaStoreUri = ContentUris.withAppendedId(
    MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
                            ImageId);

这篇关于如何删除相册视频?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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