I want to implement a feature where, if a download doesn’t start within a specified time, it should be canceled, and an error should be thrown. After reviewing various suggestions, I found that it can be achieved using a custom HttpDownloader. I've implemented the code as shown below, but it still doesn’t trigger any listener or status change.
private fun initDownloader(context: Context) {
val fetchConfiguration: FetchConfiguration =
FetchConfiguration.Builder(context).setDownloadConcurrentLimit(1)
.setHttpDownloader(getOkHttpDownloader())
.build()
fetchDownloader = Fetch.getInstance(fetchConfiguration)
fetchDownloader?.addListener(fetchDownloaderListener)
}
private fun getOkHttpDownloader(): OkHttpDownloader {
val okHttpClient: OkHttpClient = OkHttpClient.Builder()
.readTimeout(20, TimeUnit.SECONDS)
.connectTimeout(20, TimeUnit.SECONDS)
.writeTimeout(20, TimeUnit.SECONDS)
.build()
return OkHttpDownloader(
okHttpClient,
Downloader.FileDownloaderType.SEQUENTIAL
)
}
I want to implement a feature where, if a download doesn’t start within a specified time, it should be canceled, and an error should be thrown. After reviewing various suggestions, I found that it can be achieved using a custom HttpDownloader. I've implemented the code as shown below, but it still doesn’t trigger any listener or status change.