修复无限下载出错的bug
This commit is contained in:
@ -199,13 +199,15 @@ public class DownloadSchedulers implements IDownloadSchedulers {
|
|||||||
*
|
*
|
||||||
* @param entity 失败实体
|
* @param entity 失败实体
|
||||||
*/
|
*/
|
||||||
@Override public void handleFailTask(DownloadEntity entity) {
|
@Override public void handleFailTask(final DownloadEntity entity) {
|
||||||
|
new Thread(new Runnable() {
|
||||||
|
@Override public void run() {
|
||||||
final Configuration config = Configuration.getInstance();
|
final Configuration config = Configuration.getInstance();
|
||||||
if (entity.getFailNum() <= config.getReTryNum()) {
|
if (entity.getFailNum() <= config.getReTryNum()) {
|
||||||
Task task = mQueue.getTask(entity);
|
Task task = mQueue.getTask(entity);
|
||||||
mQueue.reTryStart(task);
|
mQueue.reTryStart(task);
|
||||||
try {
|
try {
|
||||||
Thread.currentThread().sleep(config.getReTryInterval());
|
Thread.sleep(config.getReTryInterval());
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
@ -213,6 +215,8 @@ public class DownloadSchedulers implements IDownloadSchedulers {
|
|||||||
startNextTask(entity);
|
startNextTask(entity);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}).start();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 启动下一个任务,条件:任务停止,取消下载,任务完成
|
* 启动下一个任务,条件:任务停止,取消下载,任务完成
|
||||||
|
@ -229,10 +229,10 @@ final class DownloadUtil implements IDownloadUtil, Runnable {
|
|||||||
conn.setConnectTimeout(mConnectTimeOut * 4);
|
conn.setConnectTimeout(mConnectTimeOut * 4);
|
||||||
conn.connect();
|
conn.connect();
|
||||||
int len = conn.getContentLength();
|
int len = conn.getContentLength();
|
||||||
if (len < 0) { //网络被劫持时会出现这个问题
|
//if (len < 0) { //网络被劫持时会出现这个问题
|
||||||
failDownload("下载失败,网络被劫持");
|
// failDownload("下载失败,网络被劫持");
|
||||||
return;
|
// return;
|
||||||
}
|
//}
|
||||||
int code = conn.getResponseCode();
|
int code = conn.getResponseCode();
|
||||||
//https://zh.wikipedia.org/wiki/HTTP%E7%8A%B6%E6%80%81%E7%A0%81
|
//https://zh.wikipedia.org/wiki/HTTP%E7%8A%B6%E6%80%81%E7%A0%81
|
||||||
//206支持断点
|
//206支持断点
|
||||||
@ -240,8 +240,9 @@ final class DownloadUtil implements IDownloadUtil, Runnable {
|
|||||||
isSupportBreakpoint = true;
|
isSupportBreakpoint = true;
|
||||||
mListener.supportBreakpoint(true);
|
mListener.supportBreakpoint(true);
|
||||||
handleBreakpoint(conn);
|
handleBreakpoint(conn);
|
||||||
} else if (code == HttpURLConnection.HTTP_OK) {
|
} else if (code == HttpURLConnection.HTTP_OK || len < 0) {
|
||||||
//在conn.setRequestProperty("Range", "bytes=" + 0 + "-");下,200为不支持断点状态
|
//在conn.setRequestProperty("Range", "bytes=" + 0 + "-");下,200为不支持断点状态
|
||||||
|
isSupportBreakpoint = false;
|
||||||
mListener.supportBreakpoint(false);
|
mListener.supportBreakpoint(false);
|
||||||
Log.w(TAG, "该下载链接不支持断点下载");
|
Log.w(TAG, "该下载链接不支持断点下载");
|
||||||
handleBreakpoint(conn);
|
handleBreakpoint(conn);
|
||||||
|
@ -257,7 +257,6 @@ public class Task {
|
|||||||
@Override public void onStart(long startLocation) {
|
@Override public void onStart(long startLocation) {
|
||||||
super.onStart(startLocation);
|
super.onStart(startLocation);
|
||||||
downloadEntity.setState(DownloadEntity.STATE_DOWNLOAD_ING);
|
downloadEntity.setState(DownloadEntity.STATE_DOWNLOAD_ING);
|
||||||
downloadEntity.setFailNum(0);
|
|
||||||
sendInState2Target(DownloadSchedulers.START);
|
sendInState2Target(DownloadSchedulers.START);
|
||||||
sendIntent(Aria.ACTION_START, startLocation);
|
sendIntent(Aria.ACTION_START, startLocation);
|
||||||
}
|
}
|
||||||
|
@ -54,10 +54,10 @@ public class SingleTaskActivity extends BaseActivity<ActivitySingleBinding> {
|
|||||||
public static final int DOWNLOAD_RESUME = 0x05;
|
public static final int DOWNLOAD_RESUME = 0x05;
|
||||||
public static final int DOWNLOAD_COMPLETE = 0x06;
|
public static final int DOWNLOAD_COMPLETE = 0x06;
|
||||||
public static final int DOWNLOAD_RUNNING = 0x07;
|
public static final int DOWNLOAD_RUNNING = 0x07;
|
||||||
private static final String DOWNLOAD_URL =
|
|
||||||
"http://static.gaoshouyou.com/d/3a/93/573ae1db9493a801c24bf66128b11e39.apk";
|
|
||||||
//private static final String DOWNLOAD_URL =
|
//private static final String DOWNLOAD_URL =
|
||||||
// "http://img13.poco.cn/mypoco/myphoto/20120828/15/55689209201208281549023849547194135_001.jpg";
|
// "http://static.gaoshouyou.com/d/3a/93/573ae1db9493a801c24bf66128b11e39.apk";
|
||||||
|
private static final String DOWNLOAD_URL =
|
||||||
|
"http://o.aolcdn.com/hss/storage/midas/3679ed444c51eca8d17a82b7da021b01/204737495/fitbit-charge-2.jpeg";
|
||||||
@Bind(R.id.progressBar) HorizontalProgressBarWithNumber mPb;
|
@Bind(R.id.progressBar) HorizontalProgressBarWithNumber mPb;
|
||||||
@Bind(R.id.start) Button mStart;
|
@Bind(R.id.start) Button mStart;
|
||||||
@Bind(R.id.stop) Button mStop;
|
@Bind(R.id.stop) Button mStop;
|
||||||
@ -124,9 +124,9 @@ public class SingleTaskActivity extends BaseActivity<ActivitySingleBinding> {
|
|||||||
mCancel.setEnabled(false);
|
mCancel.setEnabled(false);
|
||||||
setBtState(true);
|
setBtState(true);
|
||||||
|
|
||||||
//String path = Environment.getExternalStorageDirectory().getPath() + "/test.jpg";
|
String path = Environment.getExternalStorageDirectory().getPath() + "/test.jpg";
|
||||||
//Bitmap bm = BitmapFactory.decodeFile(path);
|
Bitmap bm = BitmapFactory.decodeFile(path);
|
||||||
//mImg.setImageBitmap(bm);
|
mImg.setImageBitmap(bm);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -203,10 +203,10 @@ public class SingleTaskActivity extends BaseActivity<ActivitySingleBinding> {
|
|||||||
private void start() {
|
private void start() {
|
||||||
Aria.whit(this)
|
Aria.whit(this)
|
||||||
.load(DOWNLOAD_URL)
|
.load(DOWNLOAD_URL)
|
||||||
.setDownloadPath(Environment.getExternalStorageDirectory().getPath() + "/test.apk")
|
//.setDownloadPath(Environment.getExternalStorageDirectory().getPath() + "/test.apk")
|
||||||
.setDownloadName("test.apk")
|
//.setDownloadName("test.apk")
|
||||||
//.setDownloadPath(Environment.getExternalStorageDirectory().getPath() + "/test.jpg")
|
.setDownloadPath(Environment.getExternalStorageDirectory().getPath() + "/test.jpg")
|
||||||
//.setDownloadName("test.jpg")
|
.setDownloadName("test.jpg")
|
||||||
.start();
|
.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user