清除了Android的下载列表 [英] Clear out android Downloads list

查看:125
本文介绍了清除了Android的下载列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图让该会尽我除其他事项外设备上进行一些清理的应用程序,我想它删除所有居住在我的下载目录中的文件。我用这样的方法来删除这些文件:

I am trying to make an application that will do some cleanup on my device among other things I would like it to delete all of the files residing in my Download dir. I use a method like this to delete the files:

private static void deleteFiles(File path) {
    Util.Log("deleting all files underneath " + path.getName());
    if( path.exists() && path.isDirectory() ) {
        File[] files = path.listFiles();
        for(int i=0; i<files.length; i++) {
            if(files[i].isDirectory()) {
                Util.Log(files[i].getName() + " is a dir, being recursive.");
                deleteFiles(files[i]);
            }else {
                Util.Log(files[i].getName() + " is a file, deleting it.");
                files[i].delete();
            }
        }
    }
}

这是正确删除的文件(我用的文件管理器验证,并插入到PC)。但是,如果我打开股票下载应用设备上所有的文件仍然列在里面。当我点击一个我看到一个弹出,上面写着未找到下载的文件。[再试一次] [删除]。pressing再试一次将重新下载该文件,pressing删除将删除该条目列表中。我想知道是否有一些广播或东西,我可以用它来告诉这个下载的应用程序,我希望它刷新或同步与当前的文件系统,使之认识到,这些文件已被删除。

This is properly deleting the files (I have verified with file manager and plugged in to PC). But if I open up the stock "Downloads" application on my device all of the files are still listed in there. When I click on one I get a popup that says "Downloaded file is not found. [Try again] [Delete]. Pressing try again will re-download the file, pressing delete will delete the entry in the list. I am wondering if there is some broadcast or something that I can use to tell this Downloads application that I want it to "refresh" or "sync" with the current file system so that it will recognize that the files have been deleted.

有一个类似的事情删除图像了 DCIM DIR时发生时,他们仍然会出现在股票被删除后,画廊应用程序。我能够播放导致库的应用程序刷新当前文件(然后正确地从画廊的应用程序中删除图像)一个MEDIA_MOUNTED意图。然而MEDIA_MOUNTED似乎不影响下载的应用程序。

A similar thing occurs when deleting images out of the DCIM dir, they would still appear in the stock 'Gallery' app after deleted. I was able to broadcast a MEDIA_MOUNTED intent that caused the Gallery app to "refresh" with the current files (which then properly removed the images from the Gallery app). However MEDIA_MOUNTED doesn't seem to affect the Downloads application.

有沿着相同的路线什么我可以做的,告诉下载应用程序,我希望它刷新的基础上的文件清单目前为在<$ C $中c p $ psent(或未present) > / SD卡/下载/ DIR?

Is there anything along the same lines that I can do to tell the Downloads app I want it to refresh its list based on the files currently present (or not present) in the /sdcard/Download/ dir?

推荐答案

这其实是可以清除下载的应用程序中的条目。你可以简单地使用从下载管理器中删除(ID)方法。唯一的问题是,你可能不具有下载的文件的referenceId了。如果您有本地文件URI或文件名,你可以简单地查询下载管理对于成功下载和查找ID。这似乎很繁琐,但工程。

It is actually possible to clear the entries in the Download application. You can simply use the remove(id) method from the DownloadManager. The only problem is that you probably don't have the referenceId of the downloaded file anymore. If you have the local file Uri or filename, you can simply query the DownloadManager for the successful downloads and look up the id. It seems very cumbersome, but works.

这篇关于清除了Android的下载列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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