简体   繁体   English

衡量和限制Android应用程序的总网络使用量?

[英]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. 我认为Sprint可能只剩下其中之一。

For an Android app that makes frequent Internet downloads, is there any way to measure -- and possibly cap -- the cumulative amount of data downloaded? 对于需要频繁下载互联网的Android应用,是否有任何方法可以衡量(甚至可能限制)下载的数据总量?

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 现在,每次您要下载时,都必须使用canDownload征求权限

Final Notes 最后说明

  • Keep in mind that you must keep track of the in the last X hours 请记住,您必须跟踪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. 在下载Web内容时:您可以使用RFC 2616 Fielding等人中定义的http HEAD方法了解文件的内容长度 .

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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