简体   繁体   中英

Measure and limit Android app's total web usage?

From what I read, unlimited mobile download plans are disappearing. I think Sprint might have one of the only ones left.

For an Android app that makes frequent Internet downloads, is there any way to measure -- and possibly cap -- the cumulative amount of data downloaded?

You should find an implementation for this:

A very simple example

public class DownloadSherif{
private static int MAX_DOWNLOAD_PER_DAY = 999;
private int last_24_hours_downloaded;

public DownloadSherif(){
    //get last_24_hours_downloaded from saved container
}

public boolean canDownload(int download_size){
    if((download_size+last_24_hours_downloaded)<=MAX_DOWNLOAD_PER_DAY)
         return true;
    else
         return false;
}

public void downloaded(int just_downloaded){
     last_24_hours_downloaded += just_downloaded;
}
}

Now every time you want to download you must ask permission using canDownload

Final Notes

  • Keep in mind that you must keep track of the in the last X hours
  • In downloading web content: you can know the content-length of the file using the http HEAD method defined in RFC 2616 Fielding, et al. .

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