Skip to content

Commit a710600

Browse files
author
fengjian
committed
fix the multi download error
1 parent 6afc76d commit a710600

2 files changed

Lines changed: 12 additions & 0 deletions

File tree

lesscode-core/src/main/java/com/jayfeng/lesscode/core/UpdateService.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ public class UpdateService extends Service {
4242
private File mDestDir;
4343
private File mDestFile;
4444

45+
private boolean mIsDownloading = false;
46+
4547
private Handler.Callback mHandlerCallBack = new Handler.Callback() {
4648
@Override
4749
public boolean handleMessage(Message msg) {
@@ -103,6 +105,13 @@ public void onDownloaded() {
103105

104106
@Override
105107
public int onStartCommand(Intent intent, int flags, int startId) {
108+
109+
// check downloading state
110+
if (mIsDownloading) {
111+
ToastLess.$(this, R.string.less_app_download_downloading);
112+
return super.onStartCommand(intent, flags, startId);
113+
}
114+
106115
mDownloadUrl = intent.getStringExtra($.KEY_DOWNLOAD_URL);
107116
if (TextUtils.isEmpty($.sDownloadSDPath)) {
108117
mDownloadSDPath = getPackageName() + "/download";
@@ -241,6 +250,7 @@ && checkApkFile(mDestFile.getPath())) {
241250
} else {
242251
try {
243252
sendMessage(DOWNLOAD_STATE_START);
253+
mIsDownloading = true;
244254
HttpLess.$download(mDownloadUrl, mDestFile, false, mDownloadCallBack);
245255
} catch (Exception e) {
246256
sendMessage(DOWNLOAD_STATE_FAILURE);
@@ -251,6 +261,7 @@ && checkApkFile(mDestFile.getPath())) {
251261
} else {
252262
sendMessage(DOWNLOAD_STATE_ERROR_SDCARD);
253263
}
264+
mIsDownloading = false;
254265
stopSelf();
255266
}
256267
}

lesscode-core/src/main/res/values/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
<string name="less_app_download_notification_success">下载完成。</string>
77
<string name="less_app_download_success">新版本下载成功,开始安装。</string>
88
<string name="less_app_download_failure">新版本下载失败,请稍后再试。</string>
9+
<string name="less_app_download_downloading">已经在下载中</string>
910
<string name="less_app_download_start">开始下载</string>
1011
<string name="less_app_download_install">准备安装</string>
1112
<string name="less_app_download_error_sdcard">未找到SD卡,无法下载。</string>

0 commit comments

Comments
 (0)