Resurgarm
Resurgarm

Reputation: 27

Force open and force close WiFi connectivity in an android code

I'm writing an android WIFI code to scan the nearby hot spots but I need a code to force open the wifi if it is not already opened and then force close it after the scan is done. Does anyone have an idea how to do so.

Upvotes: 0

Views: 2256

Answers (1)

Martin Cazares
Martin Cazares

Reputation: 13705

This is the way you do what you need:

WifiManager wifiManager =(WifiManager)this.context.getSystemService(Context.WIFI_SERVICE);
wifiManager.setWifiEnabled(status);

You will need some extra permissions.

uses-permission android:name="android.permission.CHANGE_WIFI_STATE"

Take on count that this might not be a good android practice, usually you would like the user to explicitly enable/disable it, so instead of programatically forcing wifi to do so, you should pop the settings activity so the user does it him self.

Regards!

Upvotes: 2

Related Questions