FileDownloader OkHttp3 Connection
A connection implemented with the OkHttp3 for FileDownloader.
Usage
The simplest way to enable the connection with the okHttp3 for FileDownloader:
// Init the FileDownloader with the OkHttp3Connection.Creator.
FileDownloader.init(context, new DownloadMgrInitialParams.InitCustomMaker()
.connectionCreator(new OkHttp3Connection.Creator()));
Alternatively, If you want to customize the OkHttp3Client
, you can provide the OkHttpClient.Builder
when create the OkHttp3Connection.Creator
:
// Enable the okHttp3 connection with the customized okHttp client builder.
final OkHttpClient.Builder builder = new OkHttpClient.Builder();
builder.connectTimeout(20_000, TimeUnit.SECONDS); // customize the value of the connect timeout.
// Init the FileDownloader with the OkHttp3Connection.Creator.
FileDownloader.setupOnApplicationOnCreate(this)
.connectionCreator(new OkHttp3Connection.Creator(builder));
Installation
Adding the following dependency to your build.gradle
file:
dependencies {
compile 'cn.dreamtobe.filedownloader:filedownloader-okhttp3-connection:1.1.0'
}
Okhttp3 Versioin and FileDownloader Version
If you want to dependency another newer version of Okhttp3 or FileDownloader, just feel free add on your dependencies
block, such as:
In this case, gradle will choose newer version dependency library instead.
dependencies {
compile'cn.dreamtobe.filedownloader:filedownloader-okhttp3-connection:1.1.0'
compile 'com.squareup.okhttp3:okhttp:3.9.1'
compile 'com.liulishuo.filedownloader:library:1.7.0'
}
If you want to dependency another lower version of Okhttp3 or FileDownloader, you need to exclude
it from filedownloader-okhttp3-connection first, then add it, such as:
dependencies {
compile('cn.dreamtobe.filedownloader:filedownloader-okhttp3-connection:1.1.0') {
exclude module: 'okhttp'
exclude group: 'com.liulishuo.filedownloader', module: 'library'
}
compile 'com.squareup.okhttp3:okhttp:3.4.2'
compile 'com.liulishuo.filedownloader:library:1.6.9'
}
Finally, please don't forget to use ./gradlew dependencies
to check out the final relationship of dependencies on your project.
Proguard Rule
because of okhttp, you need to add below proguard-rules
to your project:
-dontwarn okhttp3.*
-dontwarn okio.**
License
Copyright (C) 2016 Jacksgong(blog.dreamtobe.cn)
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.