Andrey
Andrey

Reputation: 83

Is there ability programly adjust wifi if it is disabled

Is there ability programly adjust wifi if it is disabled.

— if wifi is disabled: WifiManager wifiManager = (WifiManager) ctx.getSystemService(Context.WIFI_SERVICE); wifiManager.addNetwork(wifiConf)

addNetwork function return -1

— If wifi is enabled it works fine.


If wifi is enabled "addNetwork" function works fine and new network is added. In the same situation, but wifi is disabled "addNetwork" function return -1 and new network is not added – Andrey 46 mins ago I want adjust wifi even if wifi is disabled

thanks.

Upvotes: 0

Views: 384

Answers (2)

Zigurd
Zigurd

Reputation: 11

Install the package urfkill.

Use the command...

# rfkill unblock wifi

...to turn wifi on.

You may need to make sure the hardware switch, if there is one, is in the correct position, too.

Upvotes: 1

Mojo Risin
Mojo Risin

Reputation: 8142

You can check if you are currently connected to any network using this

ConnectivityManager manager = (ConnectivityManager) mContext.getSystemService(Context.CONNECTIVITY_SERVICE);
manager.getNetworkInfo(ConnectionManager.CONNECTION_WIFI).getState() == NetworkInfo.State.CONNECTED;

Upvotes: 0

Related Questions