Skip to content

Commit 5ed0ac2

Browse files
author
JemyCheung
committed
netReadyCheck
1 parent 591f7e6 commit 5ed0ac2

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

library/src/main/java/com/qiniu/android/storage/UploadOptions.java

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ public final class UploadOptions {
1515

1616
/**
1717
* 扩展参数,以<code>x:</code>开头的用户自定义参数
18+
* 可添加网络检测次数:netCheckTime,int类型,默认600,每增加1,检测时间增加500ms
1819
*/
1920
final Map<String, String> params;
2021

@@ -48,8 +49,18 @@ public UploadOptions(Map<String, String> params, String mimeType, boolean checkC
4849
this(params, mimeType, checkCrc, progressHandler, cancellationSignal, null);
4950
}
5051

51-
public UploadOptions(Map<String, String> params, String mimeType, boolean checkCrc,
52+
public UploadOptions(final Map<String, String> params, String mimeType, boolean checkCrc,
5253
UpProgressHandler progressHandler, UpCancellationSignal cancellationSignal, NetReadyHandler netReadyHandler) {
54+
int netReadyCheckTime = 6;
55+
try {
56+
String netCheckTime = params.get("netCheckTime");
57+
if (netCheckTime != null) {
58+
netReadyCheckTime = Integer.parseInt(netCheckTime);
59+
}
60+
} catch (Exception e) {
61+
e.printStackTrace();
62+
}
63+
Log.e("qiniutest","netCheckTime:"+netReadyCheckTime);
5364
this.params = filterParam(params);
5465
this.mimeType = mime(mimeType);
5566
this.checkCrc = checkCrc;
@@ -65,13 +76,14 @@ public boolean isCancelled() {
6576
return false;
6677
}
6778
};
79+
final int finalNetReadyCheckTime = netReadyCheckTime;
6880
this.netReadyHandler = netReadyHandler != null ? netReadyHandler : new NetReadyHandler() {
6981
@Override
7082
public void waitReady() {
7183
if (Thread.currentThread() == Looper.getMainLooper().getThread()) {
7284
return;
7385
}
74-
for (int i = 0; i < 6; i++) {
86+
for (int i = 0; i < finalNetReadyCheckTime; i++) {
7587
try {
7688
Thread.sleep(500);
7789
} catch (InterruptedException e) {

0 commit comments

Comments
 (0)