Wifi State can always be known as follows :
1) Get a WifiManager object using the method Context.getSystemService(Context.WIFI_SERVICE)
2) Use the isWifiEnabled class to know the state of Wifi.
To know the status of Data Connectivity of Cellphone, get an Instance using
TelephonyManager tm = Context.getSystemService(Context.TELEPHONY_SERVICE), and then use
tm.getDataState to know the status of data connectivity.
Now, run your BackupAgent when the return value of getDataState is TelephonyManager.DATA_DISCONNECTED and the return value of isWifiEnabled is true.
To be able to disable the backup once the connection (3G/WiFi) is dropped , create a new method is follows :
enter code here
protected void checkMyConnectivity()
{
if (tm.getDataState == TelephonyManager.DATA_DISCONNECTED && wm.isWifiEnabled==true)
return true;
else
return false;
}`
And use this code whenever you want to check the connectivity and if the return value is false, stop the upload. If you want to be very specific, use a while loop instead.