Code example for WifiManager

Methods: getWifiStatesetWifiEnabled

1
        IntentFilter intentFilter = new IntentFilter(WIFI_AP_STATE_CHANGED_ACTION);
        mContext.registerReceiver(mApStateChangeReceiver, intentFilter);
    } 
 
    public int getWifiState() { 
        return mWifiManager.getWifiState();
    } 
 
    public int getWifiApState() { 
        return (Integer) XposedHelpers.callMethod(mWifiManager, "getWifiApState");
    } 
 
    public boolean isWifiEnabled() { 
        return mWifiManager.isWifiEnabled();
    } 
 
    public void setWifiEnabled(boolean enable) {
        mWifiManager.setWifiEnabled(enable);
    } 
 
    public boolean isWifiApEnabled() { 
        return (getWifiApState() == WIFI_AP_STATE_ENABLED);
    } 
 
    @SuppressLint("NewApi") 
    public void setWifiApEnabled(boolean enable) {
        try { 
            final ContentResolver cr = mContext.getContentResolver();
 
            int wifiState = getWifiState(); 
            if (enable && (wifiState == WIFI_STATE_ENABLING ||
                    wifiState == WIFI_STATE_ENABLED)) {
                setWifiEnabled(false); 
                if (Build.VERSION.SDK_INT > 16) {
                    Settings.Global.putInt(cr, WIFI_SAVED_STATE, 1);
                } else { 
                    Settings.Secure.putInt(cr, WIFI_SAVED_STATE, 1);
                } 
            } 
 
            Class<?>[] paramArgs = new Class<?>[2];
            paramArgs[0] = WifiConfiguration.class;
            paramArgs[1] = boolean.class;
            XposedHelpers.callMethod(mWifiManager, "setWifiApEnabled", paramArgs, null, enable);
 
            if (!enable) {
                int wifiSavedState = 0;
                try { 
                    if (Build.VERSION.SDK_INT > 16) {