博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Modifying your Download Patterns Based on the Connectivity Type
阅读量:4046 次
发布时间:2019-05-24

本文共 2612 字,大约阅读时间需要 8 分钟。

Use Wi-Fi

In most cases a Wi-Fi radio will offer greater bandwidth at a significantly lower battery cost. As a result, you should endeavor to perform data transfers when connected over Wi-Fi whenever possible.

You can use a broadcast receiver to listen for connectivity changes that indicate when a Wi-Fi connection has been established to execute significant downloads, preempt scheduled updates, and potentially even temporarily increase the frequency of regular updates as described in lesson .

Use Greater Bandwidth to Download More Data Less Often

When connected over a wireless radio, higher bandwidth generally comes at the price of higher battery cost. Meaning that LTE typically consumes more energy than 3G, which is in turn more expensive than 2G.

This means that while the underlying radio state machine varies based on the radio technology, generally speaking the relative battery impact of the state change tail-time is greater for higher bandwidth radios.

At the same time, the higher bandwidth means you can prefetch more aggressively, downloading more data over the same time. Perhaps less intuitively, because the tail-time battery cost is relatively higher, it's also more efficient to keep the radio active for longer periods during each transfer session to reduce the frequency of updates.

For example, if an LTE radio is has double the bandwidth and double the energy cost of 3G, you should download 4 times as much data during each session—or potentially as much as 10mb. When downloading this much data, it's important to consider the effect of your prefetching on the available local storage and flush your prefetch cache regularly.

You can use the connectivity manager to determine the active wireless radio, and modify your prefetching routines accordingly:

ConnectivityManager cm = (ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE);TelephonyManager tm =  (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);  NetworkInfo activeNetwork = cm.getActiveNetworkInfo(); int PrefetchCacheSize = DEFAULT_PREFETCH_CACHE; switch (activeNetwork.getType()) {  case (ConnectivityManager.TYPE_WIFI):     PrefetchCacheSize = MAX_PREFETCH_CACHE; break;  case (ConnectivityManager.TYPE_MOBILE): {    switch (tm.getNetworkType()) {      case (TelephonyManager.NETWORK_TYPE_LTE |             TelephonyManager.NETWORK_TYPE_HSPAP):         PrefetchCacheSize *= 4;        break;      case (TelephonyManager.NETWORK_TYPE_EDGE |             TelephonyManager.NETWORK_TYPE_GPRS):         PrefetchCacheSize /= 2;        break;      default: break;    }    break;  }  default: break;}

转载地址:http://rxgdi.baihongyu.com/

你可能感兴趣的文章
excel 查找一个表的数据在另一个表中是否存在
查看>>
centos 7 上配置dnsmasq 同时支持ipv4和ipv6的DHCP服务
查看>>
AsyncTask、View.post(Runnable)、ViewTreeObserver三种方式总结frame animation自动启动
查看>>
Android中AsyncTask的简单用法
查看>>
解决跨网场景下,CAS重定向无法登录的问题(无需修改现有代码)
查看>>
java反编译命令
查看>>
activemq依赖包获取
查看>>
概念区别
查看>>
final 的作用
查看>>
在Idea中使用Eclipse编译器
查看>>
idea讲web项目部署到tomcat,热部署
查看>>
Idea下安装Lombok插件
查看>>
zookeeper
查看>>
Idea导入的工程看不到src等代码
查看>>
技术栈
查看>>
Jenkins中shell-script执行报错sh: line 2: npm: command not found
查看>>
8.X版本的node打包时,gulp命令报错 require.extensions.hasownproperty
查看>>
Jenkins 启动命令
查看>>
Maven项目版本继承 – 我必须指定父版本?
查看>>
通过C++反射实现C++与任意脚本(lua、js等)的交互(二)
查看>>