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.
Asked
Active
Viewed 1,651 times
1
-
No, you cannot do that (except with a rooted device, of course). You could use a variant of [this sample code](https://stackoverflow.com/a/2818173/1270789) to give the user options to turn it on and off. – Ken Y-N Jul 18 '17 at 06:19
-
Do you want to turn on network internet or wifi internet? – Amy Jul 18 '17 at 06:21
-
thanks for the reply. After rooting the device, how can I achieve the objective? – Shivam ashtikar Jul 18 '17 at 06:24
-
I want to turn on network internet – Shivam ashtikar Jul 18 '17 at 06:25
1 Answers
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