Example usage for android.net.wifi WifiManager WIFI_STATE_ENABLING

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

Introduction

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

Prototype

int WIFI_STATE_ENABLING

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

Click Source Link

Document

Wi-Fi is currently being enabled.

Usage

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

@SuppressFBWarnings("REC_CATCH_EXCEPTION")
@Nullable//w  w w .j a v  a  2  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:com.geniatech.client_phone.wifi.WifiStatusTest.java

private void setWifiStateText(int wifiState) {
    String wifiStateString;/*from  ww  w . j a v a 2s . co m*/
    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:uk.ac.horizon.ubihelper.service.PeerManager.java

private NetworkInterface getNetworkInterface() {
    if (!wifi.isWifiEnabled()) {
        Log.d(TAG, "wifi not enabled");
        return null;
    }/*from ww  w  . jav a 2 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/*  w ww.  ja va2 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;/*from   w  w w.  j a  v a  2 s  .  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;
    }
}

From source file:com.android.launcher3.widget.DigitalAppWidgetProvider.java

private void refreshWifiStatus(Context context, RemoteViews widget) {
    mWifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
    int wifiStatus = mWifiManager.getWifiState();
    if (WifiManager.WIFI_STATE_ENABLED == wifiStatus || WifiManager.WIFI_STATE_ENABLING == wifiStatus) {
        widget.setImageViewResource(R.id.wifi, R.drawable.status_wifi_on);
    } else {/*from w w  w .j  a va  2 s  .  c o  m*/
        widget.setImageViewResource(R.id.wifi, R.drawable.status_wifi_off);
    }
}