1

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.

How do I program android to look for a particular network?

Community
  • 1
  • 1
mbrc
  • 3,523
  • 13
  • 40
  • 64

1 Answers1

3

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); 
Community
  • 1
  • 1