简体   繁体   中英

Is downloading files on Android possible when the app is in background without a charger?

I'm developing an app where I need to download a 200-300 mb file from the web. Today I noticed a strange behaviour.

I always have my phone plugged to the PC with a cable with Android Monitors running in IntelliJ. Everyhing was running nice, files were downloading even when I was clicking the 'home' button in the middle of the process and I always got a notification to the menu that the downloading has finished - and it was really, complately finished.

Today I unplugged my phone from the pc/cable and opened the app. The downloading process starts but when I click 'home' and the app goes to the background, it won't finish, it won't even continue. It freezes the networking thread or something connected with it.

I read some, and I remember that some popular apps like for example 'Hearthstone' game had the same problem. If you go to the menu, downloading stops.

I figured it out that this is caused by the charger. If the phone is charging when the files are being downloaded, everything is ok.

And my question is.

Is there any Android permission that will allow me to do this?

I heard that it can be changed on the device's settings, but this is a bad solution.

Is there any possibility to download files in background, without a charger and without user's interaction with the settings?

I'll also add that I'm using LibGDX engine but it doesn't matter, I can use all of the Android's features.

I found that there are two aspects that can limit the network:

  • Restrict background data - an option that you can set on each application in Data Usage settings
  • Power saving option which automatically makes a limit on the networking and more.

Extra: when device is connected to a charger, power saving is disabled by default - that's why it was working.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM