Power-saving Android Data Transmission Method

Source: Internet
Author: User

One of the biggest disadvantages of the Android system is power. Here we will optimize the download to save power as much as possible.

1. Transfer Data together as much as possible. Unlimited read of cache data will also increase power consumption. Generally, retrieving data every 2 to 5 minutes is the best option. You can avoid downloading duplicate data.

2. Use Google Cloud Messaging for Android (GCM) to push App update notifications. In this way, you do not need to create a separate network connection for updates.

Update policy

Set a proper frequency. It is best to allow users to modify the polling frequency.

Private void enableHttpResponseCache (){

Try {

Long httpCacheSize = 10*1024*1024; // 10 MiB

File httpCacheDir = new File (getCacheDir (), "http ");

Class. forName ("android.net. http. HttpResponseCache ")

. GetMethod ("install", File. class, long. class)

. Invoke (null, httpCacheDir, httpCacheSize );

} Catch (Exception httpResponseCacheNotAvailable ){

Log. d (TAG, "HTTP response cache is unavailable .");

}

}

Modify Network Connection Mode

In most cases, Wi-Fi consumes less power than 3G.

NetworkInfo activeNetwork = cm. getActiveNetworkInfo ();

Int PrefetchCacheSize = DEFAULT_PREFETCH_CACHE;

Switch (activeNetwork. getType ()){

Case ConnectivityManager. TYPE_WIFI:

......

Case ConnectivityManager. TYPE_MOBILE:

......

Default: break;

}

Related Article

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.