如何获得下载的状态? [英] How to get status of downloading?
本文介绍了如何获得下载的状态?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用的下载管理器获取下载的状态,但它仍然无法正常工作,它永远不会跳转到条件如果(c.moveToFirst())
键,我不知道为什么。可能有人帮助我,好吗?
私人最终的BroadcastReceiver myReceiver =新的BroadcastReceiver(){
@覆盖
公共无效的onReceive(上下文的背景下,意图意图){
串动= intent.getAction();
如果(Intent.ACTION_SCREEN_OFF.equals(动作)){
下载管理器downloadMgr =(下载管理器)getSystemService(DOWNLOAD_SERVICE);
DownloadManager.Query查询=新DownloadManager.Query();
query.setFilterByStatus(DownloadManager.STATUS_FAILED|DownloadManager.STATUS_PENDING|DownloadManager.STATUS_RUNNING|DownloadManager.STATUS_SUCCESSFUL);
光标C = downloadMgr.query(查询);
如果(C == NULL){
//
}
其他 {
如果(c.moveToFirst()){
INT参数:columnIndex = c.getColumnIndex(DownloadManager.COLUMN_STATUS);
INT状态= c.getInt(参数:columnIndex);
如果(状态== DownloadManager.STATUS_RUNNING){
//做一点事
}
}
}
}
}
};
解决方案
下面是一些链接引用它。
样品code低于::
DownloadManager.Query查询= NULL;
光标C = NULL;
下载管理器下载管理器= NULL;
下载管理器=(下载管理器)getSystemService(Context.DOWNLOAD_SERVICE);
查询=新DownloadManager.Query();
如果(查询!= NULL){
query.setFilterByStatus(DownloadManager.STATUS_FAILED|DownloadManager.STATUS_PAUSED|DownloadManager.STATUS_SUCCESSFUL|
DownloadManager.STATUS_RUNNING | DownloadManager.STATUS_PENDING);
} 其他 {
返回;
}
C = downloadManager.query(查询);
如果(c.moveToFirst()){
INT状态= c.getInt(c.getColumnIndex(DownloadManager.COLUMN_STATUS));
开关(状态){
案例DownloadManager.STATUS_PAUSED:
打破;
案例DownloadManager.STATUS_PENDING:
打破;
案例DownloadManager.STATUS_RUNNING:
打破;
案例DownloadManager.STATUS_SUCCESSFUL:
打破;
案例DownloadManager.STATUS_FAILED:
打破;
}
}
I use DownloadManager for getting status of downloading, but it still doesn't work, it never jumps to condition if(c.moveToFirst())
and I don't know why. Could anybody help me, please?
private final BroadcastReceiver myReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if(Intent.ACTION_SCREEN_OFF.equals(action)) {
DownloadManager downloadMgr = (DownloadManager)getSystemService(DOWNLOAD_SERVICE);
DownloadManager.Query query = new DownloadManager.Query();
query.setFilterByStatus(DownloadManager.STATUS_FAILED|DownloadManager.STATUS_PENDING|DownloadManager.STATUS_RUNNING|DownloadManager.STATUS_SUCCESSFUL);
Cursor c = downloadMgr.query(query);
if(c==null) {
//
}
else {
if(c.moveToFirst()) {
int columnIndex = c.getColumnIndex(DownloadManager.COLUMN_STATUS);
int status = c.getInt(columnIndex);
if(status == DownloadManager.STATUS_RUNNING){
//do something
}
}
}
}
}
};
解决方案
Here are few link refer it.
sample code is below::
DownloadManager.Query query = null;
Cursor c = null;
DownloadManager downloadManager = null;
downloadManager = (DownloadManager)getSystemService(Context.DOWNLOAD_SERVICE);
query = new DownloadManager.Query();
if(query!=null) {
query.setFilterByStatus(DownloadManager.STATUS_FAILED|DownloadManager.STATUS_PAUSED|DownloadManager.STATUS_SUCCESSFUL|
DownloadManager.STATUS_RUNNING|DownloadManager.STATUS_PENDING);
} else {
return;
}
c = downloadManager.query(query);
if(c.moveToFirst()) {
int status = c.getInt(c.getColumnIndex(DownloadManager.COLUMN_STATUS));
switch(status) {
case DownloadManager.STATUS_PAUSED:
break;
case DownloadManager.STATUS_PENDING:
break;
case DownloadManager.STATUS_RUNNING:
break;
case DownloadManager.STATUS_SUCCESSFUL:
break;
case DownloadManager.STATUS_FAILED:
break;
}
}
这篇关于如何获得下载的状态?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文