From 44f3b4faf12a3ae0b258a8a7b3f41f4b3d72f840 Mon Sep 17 00:00:00 2001 From: laoyuyu <511455842@qq.com> Date: Tue, 4 Dec 2018 20:36:37 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=B9=BF=E6=92=AD=E6=94=AF?= =?UTF-8?q?=E6=8C=81=EF=BC=8C=E5=A2=9E=E5=8A=A0get=E5=8F=82=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 3 +- .../aria/core/common/http/GetDelegate.java | 86 ++++++++++++++++ .../aria/core/download/DownloadGroupTask.java | 4 + .../aria/core/download/DownloadTarget.java | 8 ++ .../aria/core/download/DownloadTask.java | 4 + .../download/downloader/ConnectionHelp.java | 36 ++++++- .../downloader/HttpFileInfoThread.java | 4 +- .../download/downloader/HttpThreadTask.java | 2 +- .../com/arialyy/aria/core/inf/AbsTask.java | 4 +- .../java/com/arialyy/aria/core/inf/ITask.java | 29 ++++++ .../aria/core/scheduler/AbsSchedulers.java | 61 +++++++++++- .../scheduler/DownloadGroupSchedulers.java | 1 + .../core/scheduler/DownloadSchedulers.java | 1 + .../aria/core/scheduler/ISchedulers.java | 61 +++++++++--- .../aria/core/scheduler/UploadSchedulers.java | 1 + app/src/main/AndroidManifest.xml | 2 +- app/src/main/assets/aria_config.xml | 5 +- .../simple/download/SingleTaskActivity.java | 97 ++++++++++++------- .../arialyy/aria/core/upload/UploadTask.java | 7 +- py/download.py | 11 +++ 20 files changed, 367 insertions(+), 60 deletions(-) create mode 100644 Aria/src/main/java/com/arialyy/aria/core/common/http/GetDelegate.java diff --git a/.gitignore b/.gitignore index 04f27198..c23ed329 100644 --- a/.gitignore +++ b/.gitignore @@ -14,4 +14,5 @@ .idea /cache *.log -uml \ No newline at end of file +uml +*.swp \ No newline at end of file diff --git a/Aria/src/main/java/com/arialyy/aria/core/common/http/GetDelegate.java b/Aria/src/main/java/com/arialyy/aria/core/common/http/GetDelegate.java new file mode 100644 index 00000000..7138f837 --- /dev/null +++ b/Aria/src/main/java/com/arialyy/aria/core/common/http/GetDelegate.java @@ -0,0 +1,86 @@ +/* + * Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.arialyy.aria.core.common.http; + +import android.text.TextUtils; +import com.arialyy.aria.core.common.RequestEnum; +import com.arialyy.aria.core.download.DownloadGroupTarget; +import com.arialyy.aria.core.download.DownloadGroupTaskEntity; +import com.arialyy.aria.core.download.DownloadTaskEntity; +import com.arialyy.aria.core.inf.AbsTarget; +import com.arialyy.aria.core.inf.IPostDelegate; +import com.arialyy.aria.core.inf.ITarget; +import com.arialyy.aria.util.ALog; +import java.util.HashMap; +import java.util.Map; + +/** + * get处理委托类 + */ +public class GetDelegate implements IPostDelegate, ITarget { + private static final String TAG = "PostDelegate"; + private TARGET mTarget; + + public GetDelegate(TARGET target) { + mTarget = target; + mTarget.getTaskEntity().setRequestEnum(RequestEnum.GET); + } + + @Override public TARGET setParams(Map params) { + mTarget.getTaskEntity().setParams(params); + if (mTarget instanceof DownloadGroupTarget) { + for (DownloadTaskEntity subTask : ((DownloadGroupTaskEntity) mTarget.getTaskEntity()).getSubTaskEntities()) { + subTask.setParams(params); + } + } + return mTarget; + } + + @Override public TARGET setParam(String key, String value) { + if (TextUtils.isEmpty(key) || TextUtils.isEmpty(value)) { + ALog.d(TAG, "key 或value 为空"); + return mTarget; + } + Map params = mTarget.getTaskEntity().getParams(); + if (params == null) { + params = new HashMap<>(); + mTarget.getTaskEntity().setParams(params); + } + params.put(key, value); + if (mTarget instanceof DownloadGroupTarget) { + for (DownloadTaskEntity subTask : ((DownloadGroupTaskEntity) mTarget.getTaskEntity()).getSubTaskEntities()) { + subTask.setParams(params); + } + } + return mTarget; + } + + @Override public void start() { + mTarget.start(); + } + + @Override public void stop() { + mTarget.stop(); + } + + @Override public void resume() { + mTarget.resume(); + } + + @Override public void cancel() { + mTarget.cancel(); + } +} diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/DownloadGroupTask.java b/Aria/src/main/java/com/arialyy/aria/core/download/DownloadGroupTask.java index 855ab3e9..927342ce 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/DownloadGroupTask.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/DownloadGroupTask.java @@ -57,6 +57,10 @@ public class DownloadGroupTask extends AbsGroupTask return new PostDelegate<>(this); } + /** + * get参数传递 + */ + public GetDelegate asGet(){ + return new GetDelegate<>(this); + } + /** * 是否使用服务器通过content-disposition传递的文件名,内容格式{@code attachment;filename=***} * 如果获取不到服务器文件名,则使用用户设置的文件名 diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/DownloadTask.java b/Aria/src/main/java/com/arialyy/aria/core/download/DownloadTask.java index 83a3f5e2..f61e8b9d 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/DownloadTask.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/DownloadTask.java @@ -68,6 +68,10 @@ public class DownloadTask extends AbsNormalTask params = taskEntity.getParams(); + if (params != null && taskEntity.getRequestEnum() == RequestEnum.GET) { + if (url.contains("?")) { + ALog.e(TAG, String.format("设置参数失败,url中已经有?,url: %s", url)); + return new URL(CommonUtil.convertUrl(url)); + } + StringBuilder sb = new StringBuilder(); + sb.append(url).append("?"); + Set keys = params.keySet(); + for (String key : keys) { + sb.append(key).append("=").append(URLEncoder.encode(params.get(key))).append("&"); + } + String temp = sb.toString(); + temp = temp.substring(0, temp.length() - 1); + return new URL(CommonUtil.convertUrl(temp)); + } else { + return new URL(CommonUtil.convertUrl(url)); + } + } /** * 转换HttpUrlConnect的inputStream流 diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/downloader/HttpFileInfoThread.java b/Aria/src/main/java/com/arialyy/aria/core/download/downloader/HttpFileInfoThread.java index 3cd5e123..14a5a9d1 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/downloader/HttpFileInfoThread.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/downloader/HttpFileInfoThread.java @@ -69,7 +69,7 @@ class HttpFileInfoThread implements Runnable { Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND); HttpURLConnection conn = null; try { - URL url = new URL(CommonUtil.convertUrl(mEntity.getUrl())); + URL url = ConnectionHelp.handleUrl(mEntity.getUrl(), mTaskEntity); conn = ConnectionHelp.handleConnection(url, mTaskEntity); conn = ConnectionHelp.setConnectParam(mTaskEntity, conn); conn.setRequestProperty("Range", "bytes=" + 0 + "-"); @@ -275,7 +275,7 @@ class HttpFileInfoThread implements Runnable { mEntity.setRedirect(true); mEntity.setRedirectUrl(newUrl); String cookies = conn.getHeaderField("Set-Cookie"); - URL url = new URL(CommonUtil.convertUrl(newUrl)); + URL url = ConnectionHelp.handleUrl(newUrl, mTaskEntity); conn = ConnectionHelp.handleConnection(url, mTaskEntity); conn = ConnectionHelp.setConnectParam(mTaskEntity, conn); conn.setRequestProperty("Cookie", cookies); diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/downloader/HttpThreadTask.java b/Aria/src/main/java/com/arialyy/aria/core/download/downloader/HttpThreadTask.java index 56fd1d08..44c23d79 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/downloader/HttpThreadTask.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/downloader/HttpThreadTask.java @@ -75,7 +75,7 @@ final class HttpThreadTask extends AbsThreadTask { + /** + * 普通下载任务 + */ + int DOWNLOAD = 1; + /** + * 上传任务 + */ + int UPLOAD = 2; + /** + * 组合任务 + */ + int DOWNLOAD_GROUP = 3; + /** + * 组合任务的子任务 + */ + int DOWNLOAD_GROUP_SUB = 4; + /** + * 未知 + */ + int OTHER = -1; + + /** + * 获取任务类型 + * + * @return {@link #DOWNLOAD}、{@link #UPLOAD}、{@link #DOWNLOAD_GROUP} + */ + int getTaskType(); + /** * 获取下载状态 */ @@ -51,6 +79,7 @@ public interface ITask { /** * 停止任务 + * * @param type {@code 0}默认操作,{@code 1}停止任务不自动执行下一任务 */ void stop(int type); diff --git a/Aria/src/main/java/com/arialyy/aria/core/scheduler/AbsSchedulers.java b/Aria/src/main/java/com/arialyy/aria/core/scheduler/AbsSchedulers.java index d2b3b087..188d8f09 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/scheduler/AbsSchedulers.java +++ b/Aria/src/main/java/com/arialyy/aria/core/scheduler/AbsSchedulers.java @@ -15,6 +15,8 @@ */ package com.arialyy.aria.core.scheduler; +import android.content.Intent; +import android.os.Bundle; import android.os.CountDownTimer; import android.os.Message; import com.arialyy.aria.core.AriaManager; @@ -26,6 +28,7 @@ import com.arialyy.aria.core.inf.AbsTask; import com.arialyy.aria.core.inf.AbsTaskEntity; import com.arialyy.aria.core.inf.GroupSendParams; import com.arialyy.aria.core.inf.IEntity; +import com.arialyy.aria.core.inf.ITask; import com.arialyy.aria.core.inf.TaskSchedulerType; import com.arialyy.aria.core.manager.TEManager; import com.arialyy.aria.core.queue.ITaskQueue; @@ -38,8 +41,7 @@ import java.util.Set; import java.util.concurrent.ConcurrentHashMap; /** - * Created by lyy on 2017/6/4. - * 事件调度器,用于处理任务状态的调度 + * Created by lyy on 2017/6/4. 事件调度器,用于处理任务状态的调度 */ abstract class AbsSchedulers> implements ISchedulers { @@ -55,6 +57,12 @@ abstract class AbsSchedulers listener = mObservers.get(getKey(obj)); @@ -155,6 +163,13 @@ abstract class AbsSchedulers 0) { Set keys = mObservers.keySet(); for (String key : keys) { @@ -254,6 +270,46 @@ abstract class AbsSchedulers extends Handler.Callback { + + String ARIA_TASK_INFO_ACTION = "ARIA_TASK_INFO_ACTION"; + /** + * 广播接收器中通过TASK_TYPE字段获取任务类型 {@link ITask#DOWNLOAD}、{@link ITask#DOWNLOAD_GROUP}、{@link + * ITask#UPLOAD}、{@link ITask#DOWNLOAD_GROUP_SUB} + */ + String TASK_TYPE = "ARIA_TASK_TYPE"; + + /** + * 广播接收器中通过TASK_STATE字段获取任务状态 普通任务的有: + *
+ * {@link #NO_SUPPORT_BREAK_POINT}、{@link #PRE}、{@link #POST_PRE}、{@link #START}、{@link + * #STOP}、{@link #FAIL}、{@link #CANCEL}、{@link #COMPLETE}、{@link #RUNNING}、{@link #RESUME}、{@link + * #WAIT} + *
+ * 子任务的有:{@link #SUB_PRE}、{@link #SUB_START}、{@link #SUB_STOP}、{@link #SUB_CANCEL}、{@link + * #SUB_FAIL}、{@link #SUB_RUNNING}、{@link #SUB_COMPLETE} + */ + String TASK_STATE = "ARIA_TASK_STATE"; + + /** + * 广播接收器中通过TASK_ENTITY字段获取任务实体 {@link DownloadEntity}、{@link UploadEntity}、{@link + * DownloadGroupEntity} + */ + String TASK_ENTITY = "ARIA_TASK_ENTITY"; + + /** + * 任务速度,单位:byte/s + */ + String TASK_SPEED = "ARIA_TASK_SPEED"; + + /** + * 任务进度 + */ + String TASK_PERCENT = "ARIA_TASK_PERCENT"; + /** - * 为任务组任务 + * 为组合任务任务 */ int IS_SUB_TASK = 0xd1; /** - * 不支持断点 + * 任务不支持断点 */ int NO_SUPPORT_BREAK_POINT = 9; /** @@ -76,37 +115,37 @@ public interface ISchedulers extends Handler.Callback { int WAIT = 10; /** - * 任务组子任务预处理 + * 组合任务子任务预处理 */ int SUB_PRE = 0xa1; /** - * 任务组子任务开始 + * 组合任务子任务开始 */ int SUB_START = 0xa2; /** - * 任务组子任务停止 + * 组合任务子任务停止 */ int SUB_STOP = 0xa3; /** - * 任务组子任务取消 + * 组合任务子任务取消 */ int SUB_CANCEL = 0xa4; /** - * 任务组子任务失败 + * 组合任务子任务失败 */ int SUB_FAIL = 0xa5; /** - * 任务组子任务执行执行中 + * 组合任务子任务执行执行中 */ int SUB_RUNNING = 0xa6; /** - * 任务组子任务完成 + * 组合任务子任务完成 */ int SUB_COMPLETE = 0xa7; diff --git a/Aria/src/main/java/com/arialyy/aria/core/scheduler/UploadSchedulers.java b/Aria/src/main/java/com/arialyy/aria/core/scheduler/UploadSchedulers.java index b832c931..1c48133b 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/scheduler/UploadSchedulers.java +++ b/Aria/src/main/java/com/arialyy/aria/core/scheduler/UploadSchedulers.java @@ -29,6 +29,7 @@ public class UploadSchedulers extends AbsSchedulers diff --git a/app/src/main/assets/aria_config.xml b/app/src/main/assets/aria_config.xml index dc934680..f866fb80 100644 --- a/app/src/main/assets/aria_config.xml +++ b/app/src/main/assets/aria_config.xml @@ -66,8 +66,10 @@ + - + + @@ -105,6 +107,7 @@ + diff --git a/app/src/main/java/com/arialyy/simple/download/SingleTaskActivity.java b/app/src/main/java/com/arialyy/simple/download/SingleTaskActivity.java index 19a2b3b9..6a86534b 100644 --- a/app/src/main/java/com/arialyy/simple/download/SingleTaskActivity.java +++ b/app/src/main/java/com/arialyy/simple/download/SingleTaskActivity.java @@ -16,8 +16,11 @@ package com.arialyy.simple.download; +import android.content.BroadcastReceiver; import android.content.ContentResolver; +import android.content.Context; import android.content.Intent; +import android.content.IntentFilter; import android.net.Uri; import android.os.Bundle; import android.os.Environment; @@ -35,6 +38,7 @@ import com.arialyy.aria.core.common.RequestEnum; import com.arialyy.aria.core.download.DownloadTarget; import com.arialyy.aria.core.download.DownloadTask; import com.arialyy.aria.core.inf.IEntity; +import com.arialyy.aria.core.scheduler.ISchedulers; import com.arialyy.aria.util.ALog; import com.arialyy.aria.util.CommonUtil; import com.arialyy.frame.util.show.L; @@ -43,6 +47,7 @@ import com.arialyy.simple.R; import com.arialyy.simple.base.BaseActivity; import com.arialyy.simple.databinding.ActivitySingleBinding; import java.io.File; +import java.util.HashMap; import java.util.Map; public class SingleTaskActivity extends BaseActivity { @@ -51,22 +56,46 @@ public class SingleTaskActivity extends BaseActivity { //"http://kotlinlang.org/docs/kotlin-docs.pdf"; //"https://atom-installer.github.com/v1.13.0/AtomSetup.exe?s=1484074138&ext=.exe"; //"http://static.gaoshouyou.com/d/22/94/822260b849944492caadd2983f9bb624.apks"; - "http://120.55.95.61:8811/ghcg/zg/武义总规纲要成果.zips"; + //"http://120.55.95.61:8811/ghcg/zg/武义总规纲要成果.zip"; //"https://yizi-kejian.oss-cn-beijing.aliyuncs.com/qimeng/package1/qmtable11.zip"; //"http://rs.0.gaoshouyou.com/d/04/1e/400423a7551e1f3f0eb1812afa1f9b44.apk"; //"http://58.210.9.131/tpk/sipgt//TDLYZTGH.tpk"; //chunked 下载 //"https://static.donguo.me/video/ip/course/pfys_1.mp4"; - //"https://www.baidu.com/link?url=_LFCuTPtnzFxVJByJ504QymRywIA1Z_T5xUxe9ZLuxcGM0C_RcdpWyB1eGjbJC-e5wv5wAKM4WmLMAS5KeF6EZJHB8Va3YqZUiaErqK_pxm&wd=&eqid=e8583fe70002d126000000065a99f864"; - //"https://d.pcs.baidu.com/file/a02c89a2d479d4fd2756f3313d42491d?fid=4232431903-250528-1114369760340736&dstime=1525491372&rt=sh&sign=FDtAERVY-DCb740ccc5511e5e8fedcff06b081203-3C13vkOkuk4TqXvVYW05zj1K0ao%3D&expires=8h&chkv=1&chkbd=0&chkpc=et&dp-logid=8651730921842106225&dp-callid=0&r=165533013"; - //"http://apk500.bce.baidu-mgame.com/game/67000/67734/20170622040827_oem_5502845.apk?r=1"; - //"https://dl.genymotion.com/releases/genymotion-2.12.1/genymotion-2.12.1-vbox.exe"; - //"http://9.9.9.59:5000/download/CentOS-7-x86_64-Minimal-1804.iso"; + //"https://www.baidu.com/link?url=_LFCuTPtnzFxVJByJ504QymRywIA1Z_T5xUxe9ZLuxcGM0C_RcdpWyB1eGjbJC-e5wv5wAKM4WmLMAS5KeF6EZJHB8Va3YqZUiaErqK_pxm&wd=&eqid=e8583fe70002d126000000065a99f864"; + //"https://d.pcs.baidu.com/file/a02c89a2d479d4fd2756f3313d42491d?fid=4232431903-250528-1114369760340736&dstime=1525491372&rt=sh&sign=FDtAERVY-DCb740ccc5511e5e8fedcff06b081203-3C13vkOkuk4TqXvVYW05zj1K0ao%3D&expires=8h&chkv=1&chkbd=0&chkpc=et&dp-logid=8651730921842106225&dp-callid=0&r=165533013"; + //"http://apk500.bce.baidu-mgame.com/game/67000/67734/20170622040827_oem_5502845.apk?r=1"; + //"https://dl.genymotion.com/releases/genymotion-2.12.1/genymotion-2.12.1-vbox.exe"; + //"http://9.9.9.50:5000/download1"; + "http://9.9.9.50:5000/download/CentOS-7-x86_64-Minimal-1804.iso"; //"https://firmwareapi.azurewebsites.net/firmware-overview?name=A19_Filament_W_IMG0038_00102411-encrypted.ota"; @Bind(R.id.start) Button mStart; @Bind(R.id.stop) Button mStop; @Bind(R.id.cancel) Button mCancel; @Bind(R.id.speeds) RadioGroup mRg; + BroadcastReceiver receiver = new BroadcastReceiver() { + @Override public void onReceive(Context context, Intent intent) { + if (intent.getAction().equals(ISchedulers.ARIA_TASK_INFO_ACTION)) { + ALog.d(TAG, "state = " + intent.getIntExtra(ISchedulers.TASK_STATE, -1)); + ALog.d(TAG, "type = " + intent.getIntExtra(ISchedulers.TASK_TYPE, -1)); + ALog.d(TAG, "speed = " + intent.getLongExtra(ISchedulers.TASK_SPEED, -1)); + ALog.d(TAG, "percent = " + intent.getIntExtra(ISchedulers.TASK_PERCENT, -1)); + ALog.d(TAG, "entity = " + intent.getParcelableExtra(ISchedulers.TASK_ENTITY).toString()); + } + } + }; + + @Override protected void onResume() { + super.onResume(); + //registerReceiver(receiver, new IntentFilter(ISchedulers.ARIA_TASK_INFO_ACTION)); + } + + @Override protected void onDestroy() { + super.onDestroy(); + unregisterReceiver(receiver); + Aria.download(this).unRegister(); + } + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Aria.download(this).register(); @@ -142,14 +171,14 @@ public class SingleTaskActivity extends BaseActivity { @Download.onTaskRunning protected void running(DownloadTask task) { ALog.d(TAG, String.format("%s_running_%s", getClass().getName(), hashCode())); //if (task.getKey().equals(DOWNLOAD_URL)) { - //Log.d(TAG, task.getKey()); - long len = task.getFileSize(); - if (len == 0) { - getBinding().setProgress(0); - } else { - getBinding().setProgress(task.getPercent()); - } - getBinding().setSpeed(task.getConvertSpeed()); + //Log.d(TAG, task.getKey()); + long len = task.getFileSize(); + if (len == 0) { + getBinding().setProgress(0); + } else { + getBinding().setProgress(task.getPercent()); + } + getBinding().setSpeed(task.getConvertSpeed()); //} } @@ -199,20 +228,20 @@ public class SingleTaskActivity extends BaseActivity { @Download.onTaskComplete void taskComplete(DownloadTask task) { //if (task.getKey().equals(DOWNLOAD_URL)) { - getBinding().setProgress(100); - Toast.makeText(SingleTaskActivity.this, "下载完成", Toast.LENGTH_SHORT).show(); - mStart.setText("重新开始?"); - //mCancel.setEnabled(false); - setBtState(true); - getBinding().setSpeed(""); - L.d(TAG, "path ==> " + task.getDownloadEntity().getDownloadPath()); - L.d(TAG, "md5Code ==> " + CommonUtil.getFileMD5(new File(task.getDownloadPath()))); - L.d(TAG, "data ==> " + Aria.download(this).getDownloadEntity(DOWNLOAD_URL)); - //Intent install = new Intent(Intent.ACTION_VIEW); - //install.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); - //File apkFile = new File(task.getDownloadPath()); - //install.setDataAndType(Uri.fromFile(apkFile), "application/vnd.android.package-archive"); - //startActivity(install); + getBinding().setProgress(100); + Toast.makeText(SingleTaskActivity.this, "下载完成", Toast.LENGTH_SHORT).show(); + mStart.setText("重新开始?"); + //mCancel.setEnabled(false); + setBtState(true); + getBinding().setSpeed(""); + L.d(TAG, "path ==> " + task.getDownloadEntity().getDownloadPath()); + L.d(TAG, "md5Code ==> " + CommonUtil.getFileMD5(new File(task.getDownloadPath()))); + L.d(TAG, "data ==> " + Aria.download(this).getDownloadEntity(DOWNLOAD_URL)); + //Intent install = new Intent(Intent.ACTION_VIEW); + //install.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + //File apkFile = new File(task.getDownloadPath()); + //install.setDataAndType(Uri.fromFile(apkFile), "application/vnd.android.package-archive"); + //startActivity(install); //} } @@ -271,6 +300,9 @@ public class SingleTaskActivity extends BaseActivity { // file.delete(); //} + Map params = new HashMap<>(); + params.put("key", "value"); + params.put("filename", "CentOS-7-x86_64-Minimal-1804.iso"); Aria.download(SingleTaskActivity.this) .load(DOWNLOAD_URL) //.addHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8") @@ -279,7 +311,9 @@ public class SingleTaskActivity extends BaseActivity { //.addHeader("Cookie", "BAIDUID=648E5FF020CC69E8DD6F492D1068AAA9:FG=1; BIDUPSID=648E5FF020CC69E8DD6F492D1068AAA9; PSTM=1519099573; BD_UPN=12314753; locale=zh; BDSVRTM=0") .useServerFileName(true) .setFilePath(path, true) - //.asPost().setParam("key", "value") + //.asGet() + .asPost() + .setParams(params) //.setExtendField("{\n" // + "\"id\":\"你的样子\"\n< > " // + "}") @@ -288,11 +322,6 @@ public class SingleTaskActivity extends BaseActivity { //.add(); } - @Override protected void onDestroy() { - super.onDestroy(); - //Aria.download(this).unRegister(); - } - @Override protected void onStop() { super.onStop(); //Aria.download(this).unRegister(); diff --git a/aria/src/main/java/com/arialyy/aria/core/upload/UploadTask.java b/aria/src/main/java/com/arialyy/aria/core/upload/UploadTask.java index a8c6d6fc..c4a38254 100644 --- a/aria/src/main/java/com/arialyy/aria/core/upload/UploadTask.java +++ b/aria/src/main/java/com/arialyy/aria/core/upload/UploadTask.java @@ -23,8 +23,7 @@ import com.arialyy.aria.core.scheduler.ISchedulers; import com.arialyy.aria.core.upload.uploader.SimpleUploadUtil; /** - * Created by lyy on 2017/2/23. - * 上传任务 + * Created by lyy on 2017/2/23. 上传任务 */ public class UploadTask extends AbsNormalTask { @@ -35,6 +34,10 @@ public class UploadTask extends AbsNormalTask { mUtil = new SimpleUploadUtil(taskEntity, (IUploadListener) mListener); } + @Override public int getTaskType() { + return UPLOAD; + } + @Override public String getKey() { return mTaskEntity.getEntity().getFilePath(); } diff --git a/py/download.py b/py/download.py index e42927df..a90dd755 100644 --- a/py/download.py +++ b/py/download.py @@ -17,5 +17,16 @@ def downloader(filename): return send_from_directory(dirpath, filename, as_attachment=True) # as_attachment=True 一定要写,不然会变成打开,而不是下载 +@app.route("/download1", methods=['POST', 'GET']) +def downloader1(): + """ + 不支持断点的下载 + """ + filename = request.values.get('filename') + data = request.values.get('key') + print data + dirpath = 'D:/test' + return send_from_directory(dirpath, filename, as_attachment=True) # as_attachment=True 一定要写,不然会变成打开,而不是下载 + if __name__ == '__main__': app.run(host='0.0.0.0', debug=True) # 需要关闭防火墙