[Android traffic] Change download mode based on network type

Source: Internet
Author: User

Reprinted from: http://blog.csdn.net/kesenhoo/article/details/7396321

modifying your Download Patterns Based on the Connectivity Type[Change the download mode based on the type of network connected]
    • Not all network types (WI-FI,3G,2G,ETC) are equal to the amount of power consumed. Not only are Wi-Fi waves much less expensive than radio waves, but different radio waves (3g,2g,lte ...). There is also the difference between using different power.
Use Wi-Fi [using Wi-Fi]
    • In most cases, Wi-Fi waves provide a relatively wide bandwidth in the case of relatively low power consumption. Therefore, we need to strive to use Wi-Fi as much as possible to pass data.
    • We can use broadcast receiver to monitor when the network connection switches to Wi-Fi, this time we can do a lot of data transfer operations, such as downloading, performing timed update operations, even at this time to increase the frequency of updates. These can all be found in the previous course.
Use Greater Bandwidth to Download greater data less Often [uses more bandwidth to download more, rather than often download]
    • When connected by radio, higher bandwidth is often associated with more power consumption. This means that LTE (a 4G network format) consumes more than 3G, and certainly more so than 2G.
    • From Lesson 1 We know what the radio state machine is all about, and generally a wider bandwidth network format will have a longer state switching time (that is, a delay from full power to standby for a period of time).
    • At the same time, wider bandwidth means that this can be more greedy for prefetch, downloading more data. Perhaps this statement is not very intuitive, because the transition time is longer, and the length of the transition time we can not control, that is, the transition time of the power consumption is almost fixed, in this case, we in each transmission session in order to reduce the frequency of the radio activation of the time to lengthen, so significantly more efficient.
    • For example: if the bandwidth and power consumption of the LTE radio is twice times that of 3G radio, we should download 4 times times the amount of data at 3G per session, or almost 10Mb (the previous article has a description 3G generally each download 2Mb). Of course, when we download this much data, we need to think about the efficiency of prefetch local storage and the need to refresh the prefetch cache frequently.
    • We can use Connectivity Manager to determine which radio waves are currently active, and to modify the prefetch operation based on different results.
  1. Connectivitymanager cm =(Connectivitymanager) Getsystemservice (Context.connectivity_service); Telephonymanager TM=(Telephonymanager) Getsystemservice (Context.telephony_service); Networkinfo activenetwork=Cm.getactivenetworkinfo (); intPrefetchcachesize =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; }  

PostScript: want to maximize efficiency and minimize the consumption of electricity, there are too many things to consider, usually, according to the functional needs of the app to choose a focus, then the premise is to understand what the impact on the efficiency of the larger, which helps us to make the best choice.


Learn from: http://developer.android.com/training/efficient-downloads/connectivity_patterns.html

Reprint Please specify the Source: Http://blog.csdn.net/kesenhoo, thank you!

[Android traffic] Change download mode based on network type

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.