Fetch icon indicating copy to clipboard operation
Fetch copied to clipboard

Download File when app is killed or in background

Open vikas-shrma opened this issue 4 years ago • 17 comments

HI i am unable to implement, download video when application is killed or in hide and no able to create notification can anyone provide me sample code for the same

any help would be appreciated Thanks

vikas-shrma avatar Dec 29 '20 12:12 vikas-shrma

@vksBhardwaj Try using Android service. If you use Kotlin, Please tell me I will update the code Sample Code

Still any doubts, Please Ask

InfiniteCoder06 avatar Dec 31 '20 06:12 InfiniteCoder06

Thanks @Hacker437 for Quick reply. I ma using Kotlin it will be very helpful. if you update code in Kotlin

Thanks

vikas-shrma avatar Jan 06 '21 13:01 vikas-shrma

Here is the gist in kotlin Gist

InfiniteCoder06 avatar Jan 08 '21 05:01 InfiniteCoder06

In your gist you have a BroadcastReceiver, not sure why you have one and you create a new instance of fetch in the onReceive method which also I am not sure what is supposed to be doing. There are now 2 different instances one in the service and one in the receiver, what is the point of this @Hacker437?

DavidKmn avatar Jan 15 '21 09:01 DavidKmn

@DavidKmn Otherwise, I cannot pause, resume, cancel the download when the button is clicked. I don't know if it can be done in a single instance only @tonyofrancis can tell.

InfiniteCoder06 avatar Jan 18 '21 04:01 InfiniteCoder06

@tonyofrancis Any thoughts on this?

DavidKmn avatar Feb 01 '21 15:02 DavidKmn

I think it is ok as long as they share same namespace

jemshit avatar Apr 13 '21 11:04 jemshit

I have a question. Should I use my Fragment class (which has resume,start,cancel buttons of a download link) instead of DownloadService class ? Or I mean can I use the codes in the DownloadService in my fragment class directly ? At the end there is an url in the DownloadService but I get the url from the user which needs an edit text.

passmanagerapp avatar Apr 16 '21 09:04 passmanagerapp

@passmanagerapp Yes you can use Fetch in a fragment.

InfiniteCoder06 avatar Apr 16 '21 09:04 InfiniteCoder06

@passmanagerapp Do you need background downloading?

InfiniteCoder06 avatar Apr 16 '21 09:04 InfiniteCoder06

@Hacker437 Yes I need background downloading

passmanagerapp avatar Apr 16 '21 11:04 passmanagerapp

@Hacker437 But fragment can't extends Service. What should I do to start downloading process in Fragment and continue to backgrond downloading when app is killed or in background.

passmanagerapp avatar Apr 16 '21 12:04 passmanagerapp

I have created a DownloadService class and DownloadCompleteReceiver as you did in the code. In fragmet, with a button I want to start the service, here is what I did for this: button.setOnclickListener { serviceIntent = Intent(context(),DownloadService::class.java) serviceIntent.putExtra("requestID",request.id) context().startService(serviceIntent) } btnPause.setOnclickListener { serviceIntent.putExtra("action","pause") }

passmanagerapp avatar Apr 16 '21 12:04 passmanagerapp

How can I use the same fetch instance and request instance in Service in my Fragment ? Now the background process is working fine, but when I open the app, the UI is reset.

passmanagerapp avatar Apr 16 '21 16:04 passmanagerapp

I am sorry I too don't know.

InfiniteCoder06 avatar Apr 27 '21 15:04 InfiniteCoder06

@vksBhardwaj Try using Android service. If you use Kotlin, Please tell me I will update the code Sample Code

Still any doubts, Please Ask

can you share your sample code. i could not find out your sample code

ravivghl avatar Jun 14 '21 19:06 ravivghl

@Hacker437 can you provide me sample code, full working in background.

ravivghl avatar Jun 14 '21 19:06 ravivghl