使用下载管理器来获得下载状态 [英] Using DownloadManager to get download status

查看:137
本文介绍了使用下载管理器来获得下载状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经搜查了很多,但我不能找到一个令人满意的答案。
我只是创造了一个方法调用时,打印在Log.i()所有可用的下载状态;这里的方法:

I've searched a lot but i can't find a satisfying answer. I've simply created a method that when called, print in Log.i() all available downloads status; Here's the method:

DownloadManager downloadManager = (DownloadManager)getSystemService(Context.DOWNLOAD_SERVICE);
DownloadManager.Query query = new DownloadManager.Query();              
Cursor c = downloadManager.query(query);

while (c.moveToNext()) {
            switch(c.getInt(c.getColumnIndex(DownloadManager.COLUMN_STATUS))) {
                  case DownloadManager.STATUS_FAILED:
                      Log.i("46dl","Download failed!");
                    break;

                  case DownloadManager.STATUS_PAUSED:
                      Log.i("46dl","Download paused!");
                    break;

                  case DownloadManager.STATUS_PENDING:
                      Log.i("46dl","Download pending!");
                    break;

                  case DownloadManager.STATUS_RUNNING:
                      Log.i("46dl","Download in progress!");
                    break;

                  case DownloadManager.STATUS_SUCCESSFUL:
                      Log.i("46dl","Download complete!");
                    break;

                  default:
                      Log.i("46dl","Download is nowhere in sight");
                    break;
                }
            }

但是,如果我开始从我的应用程序下载这仅适用;例如。

But this only works if i start a download from my app; E.g.

Request request = new Request(Uri.parse("http://www.something.com/img/img4.jpg"));
downloadManager.enqueue(request);

有关其他文件与其他应用程序下载(例如,用浏览器)没有台词是写日志。
我这么想吗?感谢您的帮助!

For other files downloading with other apps(e.g. with browser ) no lines was write in Log. Am i missing something? Thanks for the help!

推荐答案

您不能得到其他应用进行下载的下载状态。
这已被保护。

You cannot get the download status of downloads done by other apps. This is protected.

这篇关于使用下载管理器来获得下载状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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