treesAreEverywhere
treesAreEverywhere

Reputation: 3972

Android http download at very very low priority

My Android app needs to do a large (~150MB) download in the background. I am using an intent service and doing this in the background.

The problem is that this big download cloggs all other downloads.

(I'm using Volley+Glide for image downloads in the app and OkHTTP for the large file download. I would use Volley for everything, but since it's not recommended for large files, I'm using okHttp.)

Volley has a way of setting download priorities, but AFAIK, that's only used to determine WHEN a download starts, not for the % of bandwidth a d/l uses.

I was not able to find a way to set okHTTP to download at a very low priority.

Ideally, what I would like to do is just set the large okHttp download to a very low priority, and it would let everything else download.

Upvotes: 0

Views: 466

Answers (2)

Jesse Wilson
Jesse Wilson

Reputation: 40593

Create a class called ThrottledSource that extends Okio’s ForwardingSource. This class needs to limit the kilobytes per second. You can see examples of throttling a stream in MockWebServer.java.

When you're done you'll have a stream that downloads slower than it needs to. That'll free up bandwidth for other transfers.

Upvotes: 1

Mice Pápai
Mice Pápai

Reputation: 506

  1. Split the file into smaller chunks, eg. split zips
  2. Download the files with the IntentService when the app is not running (use JobScheduler)

Upvotes: 0

Related Questions