Prohibited data transfer

Context

Network

Affects

Energy Efficiency,User Conformity,User Experience

Problem

It is not checked if the user has disabled background data transmission before transmitting.

Refactorings

Check background data transfer

Resolves

Energy Efficiency,User Conformity

Affects

Solution

ConnectivityManager mConnectivity;
TelephonyManager mTelephony;

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

Note

From Developer Documentation:

This method was deprecated in API level 14. As of ICE_CREAM_SANDWICH, availability of background data depends on several combined factors, and this method will always return true. Instead, when background data is unavailable, getActiveNetworkInfo() will now appear disconnected.
ConnectivityManager.html

Links

Related