Bulk data transfer on slow network

Context

Network

Affects

Energy Efficiency,User Conformity

Problem

Transferring data over a slower network connection will consume much more power then over a fast connection.

EDGE (90kbps):
300mA * 9.1 min = 44 mAh
3G (300kbps):
210mA * 2.7 min = 9.5 mAh
WiFi (1Mbps):
330mA * 48 sec = 4.4 mAh

See: Coding for Life – Battery Life, That is

Refactorings

Check network connection

Resolves

Energy Efficiency,User Conformity

Affects

Solution

It should be first checked which network connection we are on.

ConnectivityManager mConnectivity;
TelephonyManager mTelephony;

// Skip if no connection, or background data disabled
NetworkInfo info = mConnectivity.getActiveNetworkInfo();
if (info == null || !mConnectivity.getBackgroundDataSetting()) {
    return false;
}

// Only update if WiFi or 3G is connected and not roaming
int netType = info.getType();
int netSubtype = info.getSubtype();

if (netType == ConnectivityManager.TYPE_WIFI) {
    return info.isConnected();
} else if (netType == ConnectivityManager.TYPE_MOBILE
    && netSubtype == TelephonyManager.NETWORK_TYPE_UMTS
    && !mTelephony.isNetworkRoaming()) {
    return info.isConnected();
} else {
    return false;
}

Another approach is to give the user the choice (user preference), when high volume data transfer should be done, eg. only WiFi, 3G etc. A manual trigger of the update process might also be a solution.

Links

Related