Example usage for android.net.wifi WifiManager WIFI_STATE_DISABLING

List of usage examples for android.net.wifi WifiManager WIFI_STATE_DISABLING

Introduction

In this page you can find the example usage for android.net.wifi WifiManager WIFI_STATE_DISABLING.

Prototype

int WIFI_STATE_DISABLING

To view the source code for android.net.wifi WifiManager WIFI_STATE_DISABLING.

Click Source Link

Document

Wi-Fi is currently being disabled.

Usage

From source file:Main.java

static public boolean isDisconnectedIntent(Intent intent) {
    boolean res = false;
    NetworkInfo networkInfo = (NetworkInfo) intent.getParcelableExtra(ConnectivityManager.EXTRA_NETWORK_INFO);
    if (networkInfo != null) {
        NetworkInfo.State state = networkInfo.getState();
        res = (state.equals(NetworkInfo.State.DISCONNECTING) || state.equals(NetworkInfo.State.DISCONNECTED))
                && (networkInfo.getType() == ConnectivityManager.TYPE_WIFI);

    } else {/*from  w  w  w.j a  v  a  2  s  .  c  o  m*/
        int wifiState = intent.getIntExtra(WifiManager.EXTRA_WIFI_STATE, WifiManager.WIFI_STATE_UNKNOWN);
        if (wifiState == WifiManager.WIFI_STATE_DISABLED || wifiState == WifiManager.WIFI_STATE_DISABLING) {
            res = true;
        }
    }
    return res;
}

From source file:com.piusvelte.wapdroid.StatusFragment.java

public void setWifiState(int state, String ssid, String bssid) {
    if (state == WifiManager.WIFI_STATE_ENABLED) {
        if (ssid != null) {
            mWifiState.setText(ssid);/*from  www  .  j  a  v a2 s  . c  om*/
            mWifiBSSID.setText(bssid);
        } else {
            mWifiState.setText(getString(R.string.label_enabled));
            mWifiBSSID.setText("");
        }
    } else if (state != WifiManager.WIFI_STATE_UNKNOWN) {
        mWifiState.setText((state == WifiManager.WIFI_STATE_ENABLING ? getString(R.string.label_enabling)
                : (state == WifiManager.WIFI_STATE_DISABLING ? getString(R.string.label_disabling)
                        : getString(R.string.label_disabled))));
        mWifiBSSID.setText("");
    }
}

From source file:org.servDroid.server.service.ServerService.java

@Override
public void onCreate() {
    super.onCreate();

    wifiStateChangedReceiver = new BroadcastReceiver() {

        @Override//www.j av a  2 s . c  om
        public void onReceive(Context context, Intent intent) {
            int extraWifiState = intent.getIntExtra(WifiManager.EXTRA_WIFI_STATE,
                    WifiManager.WIFI_STATE_UNKNOWN);

            switch (extraWifiState) {
            case WifiManager.WIFI_STATE_DISABLED:
                // Logger.d(TAG, "WIFI STATE DISABLED");
                break;
            case WifiManager.WIFI_STATE_DISABLING:
                if (mPreferenceHelper.isAutostopWifiEnabled() && getServerStatus() == STATUS_RUNNING) {
                    addLog("", "", "", "Wifi connection down... Stopping server");
                    stopServer();
                }
                break;
            case WifiManager.WIFI_STATE_ENABLED:
                // Logger.d(TAG, "WIFI STATE ENABLED");
                break;
            case WifiManager.WIFI_STATE_ENABLING:
                // Logger.d(TAG, "WIFI STATE ENABLING");
                break;
            case WifiManager.WIFI_STATE_UNKNOWN:
                // Logger.d(TAG, "WIFI STATE UNKNOWN");
                break;
            }

        }
    };

    registerReceiver(wifiStateChangedReceiver, new IntentFilter(WifiManager.WIFI_STATE_CHANGED_ACTION));

}

From source file:com.geniatech.client_phone.wifi.WifiStatusTest.java

private void setWifiStateText(int wifiState) {
    String wifiStateString;/*from   www  .  j  a va  2  s  .  com*/
    switch (wifiState) {
    case WifiManager.WIFI_STATE_DISABLING:
        wifiStateString = getString(R.string.wifi_state_disabling);
        break;
    case WifiManager.WIFI_STATE_DISABLED:
        wifiStateString = getString(R.string.wifi_state_disabled);
        break;
    case WifiManager.WIFI_STATE_ENABLING:
        wifiStateString = getString(R.string.wifi_state_enabling);
        break;
    case WifiManager.WIFI_STATE_ENABLED:
        wifiStateString = getString(R.string.wifi_state_enabled);
        break;
    case WifiManager.WIFI_STATE_UNKNOWN:
        wifiStateString = getString(R.string.wifi_state_unknown);
        break;
    default:
        wifiStateString = "BAD";
        Log.e(TAG, "wifi state is bad");
        break;
    }

    mWifiState.setText(wifiStateString);
}

From source file:ac.robinson.bettertogether.hotspot.HotspotManagerService.java

@SuppressFBWarnings("REC_CATCH_EXCEPTION")
@Nullable//from   w w w . j  a  v  a2 s.co m
@Override
public IBinder onBind(Intent intent) {
    if (!mIsBound) {
        //TODO: check mBluetoothAdapter not null and/or check bluetooth is available - BluetoothUtils.isBluetoothAvailable()
        mBluetoothAdapter = BluetoothUtils.getBluetoothAdapter(HotspotManagerService.this);
        mOriginalBluetoothStatus = mBluetoothAdapter.isEnabled();
        mOriginalBluetoothName = mBluetoothAdapter.getName();

        //TODO: check mWifiManager not null and/or check bluetooth is available - WifiUtils.isWifiAvailable()
        // note we need the WifiManager for connecting to other hotspots regardless of whether we can create our own
        mWifiManager = (WifiManager) getApplicationContext().getSystemService(Context.WIFI_SERVICE);

        // try to get the original state to restore later
        int wifiState = mWifiManager.getWifiState();
        switch (wifiState) {
        case WifiManager.WIFI_STATE_ENABLED:
        case WifiManager.WIFI_STATE_ENABLING:
            mOriginalWifiStatus = true;
            break;
        case WifiManager.WIFI_STATE_DISABLED:
        case WifiManager.WIFI_STATE_DISABLING:
        case WifiManager.WIFI_STATE_UNKNOWN:
            mOriginalWifiStatus = false;
            break;
        default:
            break;
        }

        // try to save the existing hotspot state
        if (CREATE_WIFI_HOTSPOT_SUPPORTED) {
            try {
                // TODO: is it possible to save/restore the original password? (WifiConfiguration doesn't hold the password)
                WifiConfiguration wifiConfiguration = WifiUtils.getWifiHotspotConfiguration(mWifiManager);
                mOriginalHotspotConfiguration = new ConnectionOptions();
                mOriginalHotspotConfiguration.mName = wifiConfiguration.SSID;
            } catch (Exception ignored) {
                // note - need to catch Exception rather than ReflectiveOperationException due to our API level (requires 19)
            }
        }

        // set up background thread for message sending - see: https://medium.com/@ali.muzaffar/dc8bf1540341
        mMessageThread = new HandlerThread("BTMessageThread");
        mMessageThread.start();
        mMessageThreadHandler = new Handler(mMessageThread.getLooper());

        // set up listeners for network/bluetooth state changes
        IntentFilter intentFilter = new IntentFilter();
        if (CREATE_WIFI_HOTSPOT_SUPPORTED) {
            intentFilter.addAction(HOTSPOT_STATE_FILTER); // Wifi hotspot states
        }
        intentFilter.addAction(WifiManager.WIFI_STATE_CHANGED_ACTION); // Wifi on/off
        intentFilter.addAction(WifiManager.NETWORK_STATE_CHANGED_ACTION); // network connection/disconnection
        intentFilter.addAction(BluetoothAdapter.ACTION_STATE_CHANGED); // Bluetooth on/off
        intentFilter.addAction(BluetoothDevice.ACTION_FOUND); // Bluetooth device found
        registerReceiver(mGlobalBroadcastReceiver, intentFilter);

        // listen for messages from our PluginMessageReceiver
        IntentFilter localIntentFilter = new IntentFilter();
        localIntentFilter.addAction(PluginIntent.ACTION_MESSAGE_RECEIVED);
        localIntentFilter.addAction(PluginIntent.ACTION_STOP_PLUGIN);
        LocalBroadcastManager.getInstance(HotspotManagerService.this).registerReceiver(mLocalBroadcastReceiver,
                localIntentFilter);

        // listen for EventBus events (from wifi/bluetooth servers)
        if (!EventBus.getDefault().isRegistered(HotspotManagerService.this)) {
            EventBus.getDefault().register(HotspotManagerService.this);
        }

        mIsBound = true;
    }

    return mMessenger.getBinder();
}

From source file:uk.ac.horizon.ubihelper.service.PeerManager.java

private NetworkInterface getNetworkInterface() {
    if (!wifi.isWifiEnabled()) {
        Log.d(TAG, "wifi not enabled");
        return null;
    }//w w w  .java2  s.com
    switch (wifi.getWifiState()) {
    case WifiManager.WIFI_STATE_ENABLED:
        // OK
        break;
    case WifiManager.WIFI_STATE_ENABLING:
        Log.d(TAG, "Wifi enabling");
        return null;
    case WifiManager.WIFI_STATE_DISABLING:
    case WifiManager.WIFI_STATE_DISABLED:
        Log.d(TAG, "wifi disabled/disabling");
        return null;
    default:
        Log.d(TAG, "Wifi state unknown");
        return null;
    }
    // has address?
    WifiInfo info = wifi.getConnectionInfo();
    int ip = info.getIpAddress();
    if (ip == 0) {
        Log.d(TAG, "waiting for an IP address");
        return null;
    }

    NetworkInterface ni = DnsUtils.getNetworkInterface(ip);
    return ni;
}

From source file:riddimon.android.asianetautologin.HttpUtils.java

/**
 * Uses TelephonyManager and WifiManager to check for network connectivity.
 * Also incorporates CONNECTING state for retry scenarios.
 * @param context/*  ww  w  .j  av  a  2  s.c om*/
 * @return ConnectionStatus
 */
public ConnectionStatus isConnectedOLD(Context context) {
    boolean data = false, wifi = false;
    boolean data_connecting = false, wifi_connecting = false;
    TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
    WifiManager wm = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
    int ds = tm.getDataState();
    int ws = wm.getWifiState();
    switch (ds) {
    case TelephonyManager.DATA_CONNECTED:
        data = true;
        break;
    case TelephonyManager.DATA_CONNECTING:
        data_connecting = true;
    default:
        data = false;
        data_connecting = false;
    }

    switch (ws) {
    case WifiManager.WIFI_STATE_ENABLING:
        wifi_connecting = true;
    case WifiManager.WIFI_STATE_DISABLING:
    case WifiManager.WIFI_STATE_DISABLED:
    case WifiManager.WIFI_STATE_UNKNOWN:
        wifi = false;
        break;
    case WifiManager.WIFI_STATE_ENABLED:
        WifiInfo wi = wm.getConnectionInfo();
        if (wi != null)
            wifi = true;
        break;
    }

    if (wifi && data)
        return ConnectionStatus.BOTH_CONNECTED;
    else if (wifi && data_connecting)
        return ConnectionStatus.WIFI_CONNECTED;
    else if (data && wifi_connecting)
        return ConnectionStatus.DATA_CONNECTED;
    else if (wifi_connecting || data_connecting)
        return ConnectionStatus.CONNECTING;
    return ConnectionStatus.NO_CONNECTION;
}

From source file:ac.robinson.bettertogether.hotspot.HotspotManagerService.java

private void connectWifiHotspot(@NonNull ConnectionOptions options) {
    Log.d(TAG, "Attempting connection via Wifi");
    switch (mWifiManager.getWifiState()) {
    case WifiManager.WIFI_STATE_ENABLED:
        Log.d(TAG, "Completing hotspot connection");
        finishConnectingWifiHotspot(options);
        break;// w ww. ja va 2s. co  m

    case WifiManager.WIFI_STATE_ENABLING:
        Log.d(TAG, "Waiting for Wifi to be enabled");
        break; // will connect in receiver

    case WifiManager.WIFI_STATE_DISABLING:
    case WifiManager.WIFI_STATE_DISABLED:
    case WifiManager.WIFI_STATE_UNKNOWN:
    default:
        Log.d(TAG, "Enabling Wifi");
        mWifiManager.setWifiEnabled(true); // will connect in receiver
        break;
    }
}