Example usage for android.net.wifi WifiManager WIFI_STATE_UNKNOWN

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

Introduction

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

Prototype

int WIFI_STATE_UNKNOWN

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

Click Source Link

Document

Wi-Fi is in an unknown state.

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 {//  w  w w  .j a v a2s .co  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.prey.events.factories.EventFactory.java

public static Event getEvent(Context ctx, Intent intent) {
    String message = "getEvent[" + intent.getAction() + "]";
    PreyLogger.d(message);//from   w w  w  . j  av a  2s . co  m
    if (BOOT_COMPLETED.equals(intent.getAction())) {
        notification(ctx);
        if (PreyConfig.getPreyConfig(ctx).isSimChanged()) {
            JSONObject info = new JSONObject();
            try {
                info.put("new_phone_number", PreyTelephonyManager.getInstance(ctx).getLine1Number());
            } catch (Exception e) {
            }
            return new Event(Event.SIM_CHANGED, info.toString());
        } else {
            return new Event(Event.TURNED_ON);
        }
    }
    if (ACTION_SHUTDOWN.equals(intent.getAction())) {
        return new Event(Event.TURNED_OFF);
    }
    if (BATTERY_LOW.equals(intent.getAction())) {
        return new Event(Event.BATTERY_LOW);
    }
    if (CONNECTIVITY_CHANGE.equals(intent.getAction())) {
        JSONObject info = new JSONObject();
        int wifiState = intent.getIntExtra(WifiManager.EXTRA_WIFI_STATE, WifiManager.WIFI_STATE_UNKNOWN);
        PreyLogger.d("__wifiState:" + wifiState);
        try {
            boolean connected = false;
            if (!PreyConnectivityManager.getInstance(ctx).isWifiConnected()) {
                Bundle extras = intent.getExtras();
                if (extras != null) {
                    if ("connected".equals(extras.getString(ConnectivityManager.EXTRA_REASON))) {
                        connected = true;
                    }
                }
            }
            if (!PreyConnectivityManager.getInstance(ctx).isMobileConnected()) {
                info.put("connected", "mobile");
                if (wifiState == WifiManager.WIFI_STATE_ENABLED) {
                    connected = true;
                }
            }
            if (connected) {
                try {
                    Thread.sleep(4000);
                } catch (Exception e) {
                }
                PreyConfig.getPreyConfig(ctx).registerC2dm();
                Intent intentFile = new Intent(ctx, FileretrievalService.class);
                ctx.startService(intentFile);
            }
        } catch (Exception e) {
        }
        return new Event(Event.WIFI_CHANGED, info.toString());
    }
    if (WIFI_STATE_CHANGED.equals(intent.getAction())) {
        JSONObject info = new JSONObject();
        int wifiState = intent.getIntExtra(WifiManager.EXTRA_WIFI_STATE, WifiManager.WIFI_STATE_UNKNOWN);
        PreyLogger.d("___wifiState:" + wifiState);

        try {
            if (wifiState == WifiManager.WIFI_STATE_ENABLED) {
                info.put("connected", "wifi");
                try {
                    Thread.sleep(2000);
                } catch (Exception e) {
                }
                PreyConfig.getPreyConfig(ctx).registerC2dm();
                Intent intentFile = new Intent(ctx, FileretrievalService.class);
                ctx.startService(intentFile);
            }
        } catch (Exception e) {
        }
        return new Event(Event.WIFI_CHANGED, info.toString());
    }
    if (AIRPLANE_MODE.equals(intent.getAction())) {
        if (!isAirplaneModeOn(ctx)) {
            notification(ctx);
            boolean connected = false;
            if (!PreyConnectivityManager.getInstance(ctx).isWifiConnected()) {
                Bundle extras = intent.getExtras();
                if (extras != null) {
                    if ("connected".equals(extras.getString(ConnectivityManager.EXTRA_REASON))) {
                        connected = true;
                    }
                }
            }
            if (!PreyConnectivityManager.getInstance(ctx).isMobileConnected()) {
                int wifiState = intent.getIntExtra(WifiManager.EXTRA_WIFI_STATE,
                        WifiManager.WIFI_STATE_UNKNOWN);
                if (wifiState == WifiManager.WIFI_STATE_ENABLED) {
                    connected = true;
                }
            }
            if (connected) {
                PreyBetaController.startPrey(ctx);
                PreyConfig.getPreyConfig(ctx).registerC2dm();
                Intent intentFile = new Intent(ctx, FileretrievalService.class);
                ctx.startService(intentFile);
            }
        }
    }

    return null;
}

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  w w  w  . j  a  v a2 s .c  o  m
            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:com.ultrafunk.network_info.receiver.WifiStatusReceiver.java

@Override
protected void updateView(Context context, RemoteViews remoteViews, Bundle widgetOptions) {
    if ((wifiState == WifiManager.WIFI_STATE_DISABLED) || (wifiState == WifiManager.WIFI_STATE_UNKNOWN)) {
        setStateColor(context, remoteViews, STATE_OFF);
        remoteViews.setTextViewText(R.id.wifiNameTextView, context.getString(R.string.wifi));
        remoteViews.setImageViewResource(R.id.wifiStateImageView, R.drawable.ic_signal_wifi_off);
        remoteViews.setViewVisibility(R.id.wifiInfoTopTextView, View.VISIBLE);
        remoteViews.setTextViewText(R.id.wifiInfoTopTextView, context.getString(R.string.tap_to_change));
        remoteViews.setViewVisibility(R.id.wifiInfoBottomTextView, View.GONE);
    } else if (wifiState == WifiManager.WIFI_STATE_ENABLED) {
        remoteViews.setImageViewResource(R.id.wifiStateImageView, R.drawable.ic_signal_wifi_on);
        remoteViews.setViewVisibility(R.id.wifiInfoTopTextView, View.VISIBLE);

        if (wifiInfo.getIpAddress() != 0) {
            setStateColor(context, remoteViews, STATE_ON);
            remoteViews.setTextViewText(R.id.wifiNameTextView, wifiInfo.getSSID().replace("\"", ""));

            if (!detailsString.isEmpty()) {
                remoteViews.setTextViewText(R.id.wifiInfoTopTextView, detailsString);
                remoteViews.setViewVisibility(R.id.wifiInfoBottomTextView, View.VISIBLE);
                remoteViews.setTextViewText(R.id.wifiInfoBottomTextView,
                        WifiUtils.getIpAddressString(wifiInfo.getIpAddress()));
            }/*from   w ww. ja  v a 2  s  .c o m*/
        } else {
            remoteViews.setViewVisibility(R.id.wifiInfoBottomTextView, View.GONE);

            if (detailedState == NetworkInfo.DetailedState.OBTAINING_IPADDR) {
                remoteViews.setTextViewText(R.id.wifiInfoTopTextView, context.getString(R.string.connecting));
            } else {
                setStateColor(context, remoteViews, STATE_ON);
                remoteViews.setTextViewText(R.id.wifiNameTextView, context.getString(R.string.wifi));
                remoteViews.setImageViewResource(R.id.wifiStateImageView, R.drawable.ic_signal_wifi_enabled);
                remoteViews.setTextViewText(R.id.wifiInfoTopTextView, context.getString(R.string.no_network));
            }
        }
    }
}

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

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

    wifiStateChangedReceiver = new BroadcastReceiver() {

        @Override//from  w  w  w.  j  ava  2  s. com
        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:ac.robinson.bettertogether.hotspot.HotspotManagerService.java

@SuppressFBWarnings("REC_CATCH_EXCEPTION")
@Nullable//from  w  w  w  .  j  a v a  2s .com
@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 w  w w  . ja va 2s  .c o  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:riddimon.android.asianetautologin.HttpUtils.java

/**
 * Uses TelephonyManager and WifiManager to check for network connectivity.
 * Also incorporates CONNECTING state for retry scenarios.
 * @param context//from  www  .  jav  a  2s  . c o  m
 * @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;//ww w  .j  a  va 2s . c  om

    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:org.metawatch.manager.Monitors.java

private static void createWifiReceiver(final Context context) {
    if (wifiReceiver != null)
        return;//from w w w.j a  va2s  .  co  m
    WifiManager wm = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
    WifiInfo info = wm.getConnectionInfo();
    if (info != null)
        SignalData.wifiBars = 1 + WifiManager.calculateSignalLevel(info.getRssi(), 4);
    wifiReceiver = new BroadcastReceiver() {
        int wifiBars = 0;

        @Override
        public void onReceive(Context c, Intent intent) {
            String action = intent.getAction();
            if (action.equals(WifiManager.WIFI_STATE_CHANGED_ACTION)) {
                if (intent.getIntExtra(WifiManager.EXTRA_WIFI_STATE,
                        WifiManager.WIFI_STATE_UNKNOWN) != WifiManager.WIFI_STATE_ENABLED) {
                    wifiBars = 0;
                }
            } else if (action.equals(WifiManager.SUPPLICANT_CONNECTION_CHANGE_ACTION)) {
                if (!intent.getBooleanExtra(WifiManager.EXTRA_SUPPLICANT_CONNECTED, false)) {
                    wifiBars = 0;
                }
            } else if (action.equals(WifiManager.NETWORK_STATE_CHANGED_ACTION)) {
                NetworkInfo netInfo = intent.getParcelableExtra(WifiManager.EXTRA_NETWORK_INFO);
                if (netInfo.getState() != NetworkInfo.State.CONNECTED) {
                    wifiBars = 0;
                } else {
                    WifiInfo wifiInfo = intent.getParcelableExtra(WifiManager.EXTRA_WIFI_INFO);
                    if (wifiInfo == null) {
                        wifiBars = 0;
                    } else {
                        wifiBars = 1 + WifiManager.calculateSignalLevel(wifiInfo.getRssi(), 4);
                    }
                }
            } else if (action.equals(WifiManager.RSSI_CHANGED_ACTION)) {
                final int newRssi = intent.getIntExtra(WifiManager.EXTRA_NEW_RSSI, -200);
                wifiBars = 1 + WifiManager.calculateSignalLevel(newRssi, 4);
            }
            if (wifiBars != SignalData.wifiBars) {
                SignalData.wifiBars = wifiBars;
                Idle.updateIdle(context, true);
            }
        }
    };
    IntentFilter f = new IntentFilter();
    f.addAction(WifiManager.WIFI_STATE_CHANGED_ACTION);
    f.addAction(WifiManager.SUPPLICANT_CONNECTION_CHANGE_ACTION);
    f.addAction(WifiManager.NETWORK_STATE_CHANGED_ACTION);
    f.addAction(WifiManager.RSSI_CHANGED_ACTION);
    context.registerReceiver(wifiReceiver, f);
}