Android http download at very very low priority - android

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.

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.

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

Related

Reducing apk size for a difference game (to allow incremental downloads)

I am working on a difference game (for android).
The apk size becomes large when I add too many levels(say 100+). I have optimized all images, etc. However the size become more than 10 Mb.
Is there any way to allow users to incrementally download 10 image files (png) at each time.
Something like only first 10 images with app install and then allowing incremental 10 images with each button click from within the app.
If I try to do it by downloading from a web server, what will I need to implement (is it async task or can I do it with something simple). In such cases, is http allowed or I need https.
I'd personally rather download that 10MB once and for all instead of downloading those additional images every time I play the game; it could be expensive to download all that data. You could of course cache them, so I don't have to download them again. And you could foreward-download an entire level of images at a time (level2.zip). But what if I suddenly beat my own high score and proceed to a new level ... and I don't have a very good internet connection at that particular moment? If you're ruining my gaming experience, I'll delete your app and give it a bad review immediately -- and so will everyone else =)
I'd definitely recommended adding all data and not depend on the user having a fast internet connection AND is willing to pay for the download.
If you app grows too big, you should look into expansion files, but I havne't used those myself so I can't tell much more than the link:
https://developer.android.com/google/play/expansion-files.html

Android - Download multiple files or a zip with all of them

I need download around 300 images to my app but I didn't find anything saying which method is the most performance/connection friendly. Should I download and unzip the file on the device or download the images one by one?
On a mobile device, making less connections is preferable, as it can be expensive to negotiate a network connection in the first place. A zip should be smaller than the individual files and it will definitely require far less data than downloading the individual files, due to less overhead as you now have one instead of 300 calls.
You should also be able to download the zip file faster than downloading the individual files, as there's less hand-shaking required to create and close connections.
Rule of thumb for me on mobiles is to do as much as possible in a call, so that you do not create and open multiple connections. I've found it more efficient to add an additional 1k or 2k payload to a call than to make multiple calls to retrieve information.

Any way to resume download from last break point Android?

I am making a download manager for my app. It works fine, but as soon as network fluctuates, I have to press retry button and it starts downloading from the beginning again. Any way to resume it from last break point?
Thanks,
Rahul
As the documentation (http://developer.android.com/training/volley/index.html) says
Volley is not suitable for large download or streaming operations, since Volley holds all responses in memory during parsing. For large download operations, consider using an alternative like DownloadManager.
However you could use the volley calls to download your big file in chunks, then when you have server instability you could just request the chunks you don't have. Note this is generally a bad idea as you're basically recreating tcp and you shouldn't do that.
create a temporary directory and store the fragment of the files that is being downloaded. after downloading concatenate the files.

How to boost the speed of downloading files in the background in Android?

I am developing an app (for both Android and iPhone). Actually, in my app I have to download lot of videos in background (using a background service, IntentService) as well as I have a screen showing the progress of downloads (using an Activity which has UI for showing download progress). But I don't know why the download speed is too less as compared to download speed for the same app in iPhone.
Also, after each download of video, I am marking that video as downloaded in the database. And this happens for all videos.
Is the database calls a problem for slow downloads of files in android?
Since the same functionality does not affect the download speed of files in iPhone.
You could try to implement some sort of download accelerator which downloads a single file by splitting it in segments and using several simultaneous connections to download these segments from a the server. First you should check if the server Accepts byte-ranges and then specify byte-ranges to download in a multi-threaded way. At last you just merge back the segments into a complete file.
Look into these documents for more info:
http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.5
Page 128:
http://www.ietf.org/rfc/rfc2068.txt
Also look up Java API URLConnection.setRequestProperty
However, I think the slow download is mostly because of your network bandwidth and server's upload speed.
Increase the Byte size of your inputstream
Update:
Take a look here

Android: Set HttpUrlConnection speed limit

is it possible to set a download speed limit for a HttpUrlConnection in Android?
My app displays data. The data is retrieved from a web server.
There are two types of data that are loaded from the web server to display them in my app:
- small files (about 1 MB)
- big files (about 100 MB)
The problem is:
When I start to downlaod a big file, which is about 100 MB and may take about 5 minutes,
my app is nearly unuseable in the meantime.
A typical scenario is:
User klicks on a big file --> big file is downloaded in the background.
In the meantime the User wants to display another little file (1 MB, should take about a few seconds to load it from server ). But the problem is, that the first downlaod (loading the big file) uses the whole bandwith and therefore the download of the small file takes about 2 minutes (instead of a few seconds).
So I would like to set a speet limit for big files (for example half of the bandwith etc.) or to implement some priority queue for downloads...
How do I set the download limit?
What I would do is either use the DownloadManager as the previous commenter suggested, if you're developing for API level 9+. The trouble is with this is that downloads are shown in the notification bar and you might not want that.
As far as I can see there is no way to limit bandwidth on a specific download using the HttpClient used with Android. But I am guessing that you are downloading the file using an AsyncTask per file, and AsyncTasks are executed serially therefore that might explain why the 2nd file doesn't start downloading.
I strongly suggest looking at RoboSpice which is perfect for this type of background downloading. I'm pretty sure you will be able to download multiple files at once as well.

Categories

Resources