标签:
转载自: http://blog.csdn.net/kesenhoo/article/details/7396321
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; }
后记:想要最大化效率与最小化电量的消耗,需要考虑的东西太多了,通常来说,会根据app的功能需求来选择有所侧重,那么前提就是需要了解到底哪些对效率的影响比较大,这有利于我们做出最优选择。
学习自:http://developer.android.com/training/efficient-downloads/connectivity_patterns.html
转载请注明出处:http://blog.csdn.net/kesenhoo,谢谢!
[Android Traffic] 根据网络类型更改下载模式
标签:
原文地址:http://www.cnblogs.com/0616--ataozhijia/p/4324453.html