|
|
@ -6,32 +6,32 @@ private BroadcastReceiver mReceiver = new BroadcastReceiver() { |
|
|
|
@Override public void onReceive(Context context, Intent intent) { |
|
|
|
@Override public void onReceive(Context context, Intent intent) { |
|
|
|
String action = intent.getAction(); |
|
|
|
String action = intent.getAction(); |
|
|
|
//可以通过intent获取到下载实体,下载实体中包含了各种下载状态 |
|
|
|
//可以通过intent获取到下载实体,下载实体中包含了各种下载状态 |
|
|
|
DownloadEntity entity = intent.getParcelableExtra(DownloadManager.ENTITY); |
|
|
|
DownloadEntity entity = intent.getParcelableExtra(Aria.ENTITY); |
|
|
|
switch (action) { |
|
|
|
switch (action) { |
|
|
|
case DownloadManager.ACTION_PRE: //预处理 |
|
|
|
case Aria.ACTION_PRE: //预处理 |
|
|
|
break; |
|
|
|
break; |
|
|
|
case DownloadManager.ACTION_POST_PRE: //预处理完成 |
|
|
|
case Aria.ACTION_POST_PRE: //预处理完成 |
|
|
|
//预处理完成,便可以获取文件的下载长度了 |
|
|
|
//预处理完成,便可以获取文件的下载长度了 |
|
|
|
len = entity.getFileSize(); |
|
|
|
len = entity.getFileSize(); |
|
|
|
break; |
|
|
|
break; |
|
|
|
case DownloadManager.ACTION_START: //开始下载 |
|
|
|
case Aria.ACTION_START: //开始下载 |
|
|
|
L.d(TAG, "download start"); |
|
|
|
L.d(TAG, "download start"); |
|
|
|
break; |
|
|
|
break; |
|
|
|
case DownloadManager.ACTION_RESUME: //恢复下载 |
|
|
|
case Aria.ACTION_RESUME: //恢复下载 |
|
|
|
L.d(TAG, "download resume"); |
|
|
|
L.d(TAG, "download resume"); |
|
|
|
long location = intent.getLongExtra(DownloadManager.CURRENT_LOCATION, 1); |
|
|
|
long location = intent.getLongExtra(DownloadManager.CURRENT_LOCATION, 1); |
|
|
|
break; |
|
|
|
break; |
|
|
|
case DownloadManager.ACTION_RUNNING: //下载中 |
|
|
|
case Aria.ACTION_RUNNING: //下载中 |
|
|
|
long current = intent.getLongExtra(DownloadManager.CURRENT_LOCATION, 0); |
|
|
|
long current = intent.getLongExtra(DownloadManager.CURRENT_LOCATION, 0); |
|
|
|
break; |
|
|
|
break; |
|
|
|
case DownloadManager.ACTION_STOP: //停止下载 |
|
|
|
case Aria.ACTION_STOP: //停止下载 |
|
|
|
L.d(TAG, "download stop"); |
|
|
|
L.d(TAG, "download stop"); |
|
|
|
break; |
|
|
|
break; |
|
|
|
case DownloadManager.ACTION_COMPLETE: //下载完成 |
|
|
|
case Aria.ACTION_COMPLETE: //下载完成 |
|
|
|
break; |
|
|
|
break; |
|
|
|
case DownloadManager.ACTION_CANCEL: //取消下载 |
|
|
|
case Aria.ACTION_CANCEL: //取消下载 |
|
|
|
break; |
|
|
|
break; |
|
|
|
case DownloadManager.ACTION_FAIL: // 下载失败 |
|
|
|
case Aria.ACTION_FAIL: // 下载失败 |
|
|
|
break; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -44,15 +44,15 @@ private BroadcastReceiver mReceiver = new BroadcastReceiver() { |
|
|
|
super.onResume(); |
|
|
|
super.onResume(); |
|
|
|
IntentFilter filter = new IntentFilter(); |
|
|
|
IntentFilter filter = new IntentFilter(); |
|
|
|
filter.addDataScheme(getPackageName()); |
|
|
|
filter.addDataScheme(getPackageName()); |
|
|
|
filter.addAction(DownloadManager.ACTION_PRE); |
|
|
|
filter.addAction(Aria.ACTION_PRE); |
|
|
|
filter.addAction(DownloadManager.ACTION_POST_PRE); |
|
|
|
filter.addAction(Aria.ACTION_POST_PRE); |
|
|
|
filter.addAction(DownloadManager.ACTION_RESUME); |
|
|
|
filter.addAction(Aria.ACTION_RESUME); |
|
|
|
filter.addAction(DownloadManager.ACTION_START); |
|
|
|
filter.addAction(Aria.ACTION_START); |
|
|
|
filter.addAction(DownloadManager.ACTION_RUNNING); |
|
|
|
filter.addAction(Aria.ACTION_RUNNING); |
|
|
|
filter.addAction(DownloadManager.ACTION_STOP); |
|
|
|
filter.addAction(Aria.ACTION_STOP); |
|
|
|
filter.addAction(DownloadManager.ACTION_CANCEL); |
|
|
|
filter.addAction(Aria.ACTION_CANCEL); |
|
|
|
filter.addAction(DownloadManager.ACTION_COMPLETE); |
|
|
|
filter.addAction(Aria.ACTION_COMPLETE); |
|
|
|
filter.addAction(DownloadManager.ACTION_FAIL); |
|
|
|
filter.addAction(Aria.ACTION_FAIL); |
|
|
|
registerReceiver(mReceiver, filter); |
|
|
|
registerReceiver(mReceiver, filter); |
|
|
|
} |
|
|
|
} |
|
|
|
``` |
|
|
|
``` |
|
|
|