targetSdkVersion 29,Android 10,cause:ERROR realCause:java.io.IOException: The current offset on block-info isn't update correct, 2920 != 10006923 on 1
See original GitHub issueOkDownload Version
okdownload:1.0.7
Problem Describe
targetSdkVersion 29,Android 10,taskEnd with “cause:ERROR realCause:java.io.IOException: The current offset on block-info isn’t update correct, 2920 != 10006923 on 1”.
Log
2020-11-11 17:12:41.688 16243-16243/cn.nova.phone E/DownloadTask: cause:ERROR realCause:java.io.IOException: The current offset on block-info isn’t update correct, 2920 != 10006923 on 1 2020-11-11 16:43:01.934 3505-20805/? I/DownloadState: 10356 stop download, curr: 176184008, base: 176167960, delta: 16048 2020-11-11 16:43:01.934 3505-20805/? I/DownloadState: @@@@@@@@@@@@ uid :10356 download :false
download file link: https://www.bus365.com/public/phoneClient/BUS365.apk
{
String apkUrl = "https://www.bus365.com/public/phoneClient/BUS365.apk";
if (StringUtil.isEmpty(apkUrl)) {
return;
}
//不拼接时间将开启断点续传,正式的cdn有支持,开发模拟都不支持。
Map<String, String> params = new HashMap<>(0);
//拼接时间
params.put("time", String.valueOf(System.currentTimeMillis()));
//拼接参数获取最后的url
apkUrl = UrlSkipTool.getLoadUrl(apkUrl, params);
String sdpath = Util.getDiskCacheDir(getApplicationContext());
String name = getString(R.string.app_name) + ".apk";
//下载
DownloadTask.Builder builder = new DownloadTask.Builder(apkUrl, sdpath, name)
// the minimal interval millisecond for callback progress
.setMinIntervalMillisCallbackProcess(500)
//Set whether need to pre allocate length for the file after get the resource-length from trial-connection.
.setPreAllocateLength(true)
// do re-download even if the task has already been completed in the past.
.setPassIfAlreadyCompleted(false);
builder.addHeader("Accept-Encoding", "*");
mDownloadTask = builder.build();
mDownloadTask.enqueue(new DownloadListener4() {
@Override
public void taskStart(@NonNull DownloadTask task) {
if (mDownloadHandler != null) {
Message msg = mDownloadHandler.obtainMessage(INT_UPDATE_PROGRESS);
msg.obj = 0;
mDownloadHandler.sendMessage(msg);
}
}
@Override
public void connectStart(@NonNull DownloadTask task, int blockIndex, @NonNull Map<String, List<String>> requestHeaderFields) {
if (mDownloadHandler != null) {
Message msg = mDownloadHandler.obtainMessage(INT_UPDATE_PROGRESS);
msg.obj = 0;
mDownloadHandler.sendMessage(msg);
}
}
@Override
public void connectEnd(@NonNull DownloadTask task, int blockIndex, int responseCode, @NonNull Map<String, List<String>> responseHeaderFields) {
}
@Override
public void infoReady(DownloadTask task, @NonNull BreakpointInfo info, boolean fromBreakpoint, @NonNull Listener4Assist.Listener4Model model) {
int totalLength = (int) info.getTotalLength();
if (totalLength > 0) {
totalFile = totalLength;
}
if (mDownloadHandler != null) {
Message msg = mDownloadHandler.obtainMessage(INT_UPDATE_PROGRESS);
msg.obj = 0;
mDownloadHandler.sendMessage(msg);
}
}
@Override
public void progressBlock(DownloadTask task, int blockIndex, long currentBlockOffset) {
}
@Override
public void progress(DownloadTask task, long currentOffset) {
//进度更新
int b = 0;
if (totalFile > 0) {
b = (int) ((currentOffset * 1.0f / totalFile) * 100);
}
if (mDownloadHandler != null) {
Message msg = mDownloadHandler.obtainMessage(INT_UPDATE_PROGRESS);
msg.obj = b;
mDownloadHandler.sendMessage(msg);
}
}
@Override
public void blockEnd(DownloadTask task, int blockIndex, BlockInfo info) {
}
@Override
public void taskEnd(DownloadTask task, EndCause cause, @Nullable Exception realCause, @NonNull Listener4Assist.Listener4Model model) {
if (mDownloadHandler == null) {
return;
}
if (cause == EndCause.COMPLETED) {
//下载完成
File file = task.getFile();
Message msg = mDownloadHandler.obtainMessage(INT_UPDATE_DONE);
msg.obj = file;
mDownloadHandler.sendMessage(msg);
} else if (cause == EndCause.CANCELED) {
Logger.e("DownloadTask", "cause:" + String.valueOf(cause) + " realCause:" + realCause);
} else {
//下载出错
Message msg = mDownloadHandler.obtainMessage(INT_UPDATE_FAIL);
mDownloadHandler.sendMessage(msg);
Logger.e("DownloadTask", "cause:" + String.valueOf(cause) + " realCause:" + realCause);
}
}
});
}
/**
* 拼接参数获取需要load的url
*
* @param url 地址
* @param params 参数
* @return
*/
public static String getLoadUrl(String url, Map<String, String> params) {
if (TextUtils.isEmpty(url) || params == null) {
return url;
}
Uri.Builder builder = Uri.parse(url).buildUpon();
for (Map.Entry<String, String> entry : params.entrySet()) {
if (TextUtils.isEmpty(entry.getKey())) {
continue;
}
builder.appendQueryParameter(entry.getKey(), entry.getValue());
}
return builder.toString();
}
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:15
Top Results From Across the Web
Behavior changes: apps targeting API 29+ - Android Developers
Android 10 includes updated system behavior changes that may affect your app. The changes listed in this document apply exclusively to apps that...
Read more >下载过程中报错The current offset on block-info isn't update ...
androidX(10)版本,下载过程中报错The current offset on block-info isn't update correct,块信息上的当前偏移量未正确更新,解决办法.
Read more >Environment.getExternalStorageDirectory() deprecated in API ...
This attribute is "false" by default on apps targeting Android 10 or ... you only need this once you update your targetSdkVersion to...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
same issue
临时修复方案,参考链接,原文链接:https://blog.csdn.net/Kstar_Ming/article/details/115909863