khushpanchal / Ketch

An Android File downloader library based on WorkManager with pause and resume support.
https://medium.com/@khush.panchal123/ketch-android-file-downloader-library-7369f7b93bd1
395 stars 26 forks source link

How to start the download automatically. #12

Closed hamza0786 closed 1 month ago

hamza0786 commented 1 month ago

Hi Brother!

how can i start the download automatically without going to the mainfragment by passing the download url through Bundle arguments.

like this for example:

https://github.com/user-attachments/assets/e1b63a4c-24d5-478a-a84f-7850a28d49e9

khushpanchal commented 1 month ago

You can download from anywhere it may not necessarily be MainFragment or any screen. Ketch is a singleton class, you can inject it in any of your class as per your use case and call download function. For observing, you can observe it in any scope, just call observeDownloads function. In case you do not want to inject the class externally just call like this from any class.

val ketch = Ketch.builder().build(context)
ketch.download(url, fileName, path)

CoroutineScope(Dispatchers.IO).launch {
    ketch.observeDownloads().collect{ list->}
}

Make sure to cancel the scope at appropriate place to avoid unnecessary observing

hamza0786 commented 1 month ago

Hi its working but asa i close the app or put app in background the download stopped progressing and then it Failed any solution? of this will be appericiated!

hamza0786 commented 1 month ago

no need i figured it out. thanks for reaching me out!