I want to manually close wifi and data roaming in android. After finishing with processing some data i want to enable it back. How can i do this programatically?
I only find this howto but is not working in my android 4.
I want to manually close wifi and data roaming in android. After finishing with processing some data i want to enable it back. How can i do this programatically?
I only find this howto but is not working in my android 4.
For wifi (requires android.permission.CHANGE_WIFI_STATE
):
WifiManager wm = (WifiManager) getSystemService(Context.WIFI_SERVICE);
wm.setWifiEnabled(true);
For data (requires android.permission.CHANGE_NETWORK_STATE
, from here):
ConnectivityManager mgr = (ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE);
Method dataMtd = ConnectivityManager.class.getDeclaredMethod("setMobileDataEnabled", boolean.class);
dataMtd.setAccessible(true);
dataMtd.invoke(mgr, true/false);