1

I am new in Android developer community. I just want to ask if there is a way to turn ON or OFF the internet connectivity of android device through app. Is there any permission for that so that app can disconnect the device from internet? Any suggestion will be helpful.

Shivam ashtikar
  • 1,188
  • 1
  • 7
  • 7

1 Answers1

6

add your manifest this permissions

<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE"/>
<uses-permission android:name="android.permission.UPDATE_DEVICE_STATS" />
<uses-permission android:name="android.permission.WAKE_LOCK" />

then you can enable or disable your wifi

WifiManager wifi = (WifiManager) getSystemService(Context.WIFI_SERVICE);
wifi.setWifiEnabled(true);

or

wifi.setWifiEnabled(false);
6155031
  • 4,171
  • 6
  • 27
  • 56
  • IMO this will provide the option of enabling Internet over WiFi. But it doesn't cover enable/disable internet over Mobile Data. – PasinduJay Jul 18 '17 at 06:31
  • You cannot access mobile data on / off programmaticaly above android 4.4 .It have been made stopped for security reasons – 6155031 Jul 18 '17 at 06:32
  • Is there any other way to access mobile data on/off programmatically https://stackoverflow.com/a/26382149/8139535 this will work If the app is system app – Shivam ashtikar Jul 18 '17 at 06:59