0

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?

Arun J
  • 687
  • 4
  • 14
  • 27
  • 1
    https://stackoverflow.com/questions/3930990/android-how-to-enable-disable-wifi-or-internet-connection-programmatically – AskNilesh Apr 27 '18 at 04:59
  • 1
    You can't tweak System settings. It's not possible – Rahul Singh Chandrabhan Apr 27 '18 at 05:04
  • 1
    Possible 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
  • 1
    then 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 Answers3

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
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
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.