android wifi 开关代码

private WifiManager mWm;
                mWm = (WifiManager) this.getSystemService(Context.WIFI_SERVICE);
                    if (mWm.isWifiEnabled()) {
                            mWm.setWifiEnabled(false);
                            txt.setText("Wifi OFF");
                    }
                    else {
                            mWm.setWifiEnabled(true);
                            txt.setText("Wifi ON");
                    }

Manifest中要声明如下权限:
           <uses-permission android:name="android.permission.ACCESS_WIFI_STATE"></uses-permission>
        <uses-permission android:name="android.permission.CHANGE_WIFI_STATE"></uses-permission>

你可能感兴趣的:(android)