我使用DownloadManager检查是否有正在进行的下载,并且它工作正常(我认为它工作正常,请参阅下面的编辑)。
我需要的是在DownloadManager完成所有下载后获得通知(例如,其他应用程序请求Google Play),因此在我的应用程序中,我将采取特定的操作。
EDIT1:
以下代码总是转到(否则,光标始终为空),即使其他应用程序当前正在下载,为什么?它是否检查我的应用程序是否只下载了一个下载,或者是否一般都有下载?
EDIT2:
我在{Edit1} Using DownloadManager to get download status找到了同样的问题,答案是'你无法获得其他应用程序完成的下载下载状态。这是受保护的。'
DownloadManager downloadManager = (DownloadManager) this.getSystemService(Context.DOWNLOAD_SERVICE);
DownloadManager.Query query = null;
Cursor c = null;
query = new DownloadManager.Query();
if(query!=null)
{
query.setFilterByStatus(DownloadManager.STATUS_FAILED|DownloadManager.STATUS_PAUSED|DownloadManager.STATUS_SUCCESSFUL|
DownloadManager.STATUS_RUNNING|DownloadManager.STATUS_PENDING);
c = downloadManager.query(query);
if(c.moveToFirst())
{
int status = c.getInt(c.getColumnIndex(DownloadManager.COLUMN_STATUS));
switch(status)
{
case DownloadManager.STATUS_PAUSED:
Toast.makeText(getBaseContext(), "STATUS_PAUSED", Toast.LENGTH_SHORT).show();
break;
case DownloadManager.STATUS_PENDING:
Toast.makeText(getBaseContext(), "STATUS_PENDING", Toast.LENGTH_SHORT).show();
break;
case DownloadManager.STATUS_RUNNING:
Toast.makeText(getBaseContext(), "STATUS_RUNNING", Toast.LENGTH_LONG).show();
//Here I want to wait until no more downloads to make an action, how to wait.
break;
case DownloadManager.STATUS_SUCCESSFUL:
Toast.makeText(getBaseContext(), "STATUS_SUCCESSFUL", Toast.LENGTH_SHORT).show();
break;
case DownloadManager.STATUS_FAILED:
Toast.makeText(getBaseContext(), "STATUS_FAILED", Toast.LENGTH_SHORT).show();
break;
}
}
else
{
//Toast.makeText(getBaseContext(), "No Download In Progress", Toast.LENGTH_SHORT).show();
//Here I'll make some action, but the problem that even when there is a download in progress, else if being called, why?!
}
c.close();
}
答案 0 :(得分:0)
通过互联网搜索后,我发现除了我自己的下载外,无法检测到DownloadManager状态。