Android Multi-Thread Download library.
The lib hasn't been fully tested and released yet. If you find some bugs, welcome to post issues to me.
- Step 1: Add permission in 'AndroidManifest.xml'
<uses-permissionandroid:name="android.permission.INTERNET" />
<uses-permissionandroid:name="android.permission.WRITE_EXTERNAL_STORAGE" />- Step 2: Add "compile project(':library')" in your 'build.gradle' file.(Maven or jCenter support will be coming soon)
- Step 3: Config it in your Application class
privatevoidinitDownloader() {
DownloadConfigurationconfiguration = newDownloadConfiguration();
configuration.setMaxThreadNum(10);
configuration.setThreadNum(3);
DownloadManager.getInstance().init(getApplicationContext(), configuration);
}- Step 4: Just use it!
// first: build a DownloadRequest:finalDownloadRequestrequest = newDownloadRequest.Builder()
.setName(appInfo.getName() + ".apk")
.setUri(appInfo.getUrl())
.setFolder(mDownloadDir)
.build();
// download:// the tag here, you can simply use download uri as your tag;DownloadManager.getInstance().download(request, tag, newCallBack() {
@OverridepublicvoidonStarted() {
}
@OverridepublicvoidonConnecting() {
}
@OverridepublicvoidonConnected(longtotal, booleanisRangeSupport) {
}
@OverridepublicvoidonProgress(longfinished, longtotal, intprogress) {
}
@OverridepublicvoidonCompleted() {
}
@OverridepublicvoidonDownloadPaused() {
}
@OverridepublicvoidonDownloadCanceled() {
}
@OverridepublicvoidonFailed(DownloadExceptione) {
}
});
//pauseDownloadManager.getInstance().pause(tag);
//pause allDownloadManager.getInstance().pauseAll();
//cancelDownloadManager.getInstance().cancel(tag);
//cancel allDownloadManager.getInstance().cancelAll();
//deleteDownloadManager.getInstance().delete(tag);If you would like to contribute code you can do so through GitHub by forking the repository and sending a pull request.
- link: http://www.imooc.com/learn/363
- Google Volley.
- Github: github.com/aspsine
- Email: littleximail@gmail.com
- Linkedin: cn.linkedin.com/in/aspsine
Copyright 2015 Aspsine. All rights reserved.
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.
