Android的媒体扫描:如何删除文件? [英] Android's Media Scanner: How do I remove files?

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

问题描述

我正在写一个应用程序,除去可能或可能不被列在媒体库,例如音乐或图片的类型中的任何一个文件。虽然我可以使用 MediaScannerConnection.scanFile 方法的添加的文件到媒体库中似乎没有被任何电话通知的服务,该文件已被删除。发送它不再存在不会导致所期望的行为或者文件的路径。我应该如何去删除从库项目在Android上存储不再存在?

I'm writing an app that removes files that may or may not be listed in any one of the types of media libraries such as music or pictures. While I can use the MediaScannerConnection.scanFile method to add files to the media library there doesn't seem to be any call to notify the service that the file has been removed. Sending it the path of the file that no longer exists doesn't result in the desired behavior either. How should I go about removing items from the library that no longer exist on the Android storage?

推荐答案

下面的工作很适合我。您可以删除或使用该添加文件。

The following works well for me. You can delete or add files using this.

MediaScannerConnection.scanFile(
                context,
                new String[]{fileToDelete, fileToAdd},
                null, null);

这篇关于Android的媒体扫描:如何删除文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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