I have Two buttons to disable WIFI and GPS functionality. On Clicking on button user will not allowed to change the state of gps or wifi. it has to completely block the wifi and gps. Any one having solutions?
Asked
Active
Viewed 106 times
0
-
1https://stackoverflow.com/questions/3930990/android-how-to-enable-disable-wifi-or-internet-connection-programmatically – AskNilesh Apr 27 '18 at 04:59
-
1You can't tweak System settings. It's not possible – Rahul Singh Chandrabhan Apr 27 '18 at 05:04
-
1Possible duplicate of [Android: How to Enable/Disable Wifi or Internet Connection Programmatically](https://stackoverflow.com/questions/3930990/android-how-to-enable-disable-wifi-or-internet-connection-programmatically) – Subin Babu Apr 27 '18 at 05:04
-
1then how App locker are able to block wifi? @RahulChandrabhan – Rashmi ranjana Apr 27 '18 at 06:37
-
@SubinBabu no it is not. that question is about enable or disable wifi. here question is to block wifi facility to user. – Rashmi ranjana Apr 27 '18 at 06:46
-
Sorry to say, Reaccept a new answer that is answered after my answer after a long time. This is a pure violation of StackOverflow policies to get a reputation. Also, the answer is exactly the same answer as me. – Subin Babu Jun 11 '18 at 06:06
3 Answers
0
WifiManager wifiManager = (WifiManager)this.context.getSystemService(Context.WIFI_SERVICE);
wifiManager.setWifiEnabled(status);
also, add permission. You can find the details from here

AskNilesh
- 67,701
- 16
- 123
- 163

Subin Babu
- 1,515
- 2
- 24
- 50
-
Sorry to say. this is not requirement. i want to completely block wifi. if i will use that code. if i will click on wifi it will get on. – Rashmi ranjana Apr 27 '18 at 06:36
-
1
0
You also need the following permissions in your manifest file:
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
WifiManager wifiManager = (WifiManager) this.context.getSystemService(Context.WIFI_SERVICE);
wifiManager.setWifiEnabled(status);

ColdFire
- 6,764
- 6
- 35
- 51

Deepanshu Namdeo
- 159
- 1
- 12
-
Sorry to say. this is not requirement. i want to completely block wifi. if i will use that code. if i will click on wifi it will get on. – Rashmi ranjana Apr 27 '18 at 06:36
-
-
-
-
i have created a Broadcast Receiver to handle that. when someone is clicking to disable wifi i am calling that receiver. and enabling it. but while making it enable the receiver catch that event and going to a continuous loop. – Rashmi ranjana Apr 27 '18 at 09:42
0
to Block wifi Completely we need a Broadcast receiver who will detect the event for wifi status change. And if the status is on we need to make it off.. by this i resoled it issue.

Rashmi ranjana
- 92
- 9