List of usage examples for android.net.wifi WifiManager WIFI_STATE_DISABLED
int WIFI_STATE_DISABLED
To view the source code for android.net.wifi WifiManager WIFI_STATE_DISABLED.
Click Source Link
From source file:Main.java
public static boolean isWifiDisabled(WifiManager wifi) { return wifi.getWifiState() == WifiManager.WIFI_STATE_DISABLED; }
From source file:Main.java
public static int getWifiState(Context context) { WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); if (wifiManager != null) { return wifiManager.getWifiState(); }/* ww w. ja v a 2 s .c o m*/ return WifiManager.WIFI_STATE_DISABLED; }
From source file:Main.java
public static void toggleWifi(Context context) { WifiManager wifi_manager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); if (wifi_manager != null) { switch (wifi_manager.getWifiState()) { case WifiManager.WIFI_STATE_DISABLED: wifi_manager.setWifiEnabled(true); break; case WifiManager.WIFI_STATE_ENABLED: wifi_manager.setWifiEnabled(false); break; }/* w w w. j av a2s . c om*/ } }
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 va 2 s .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.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 w w . j a 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:com.compal.wifitest.WifiTestCase.java
public boolean checkWifiOnOffState(int toTest) { long startTime = System.currentTimeMillis(); long tempTime = startTime; //debug while ((System.currentTimeMillis() - startTime) < LONG_TIMEOUT) { if (toTest == test_WifiOn) if (mWifiManager.getWifiState() == WifiManager.WIFI_STATE_ENABLED && mWifiManager.isWifiEnabled()) { Log.i(tag, "mWifiManager.getWifiState() == WifiManager.WIFI_STATE_ENABLED"); return true; }/*from ww w. ja va 2s . c o m*/ if (toTest == test_WifiOff) { if (mWifiManager.getWifiState() == WifiManager.WIFI_STATE_DISABLED && !mWifiManager.isWifiEnabled()) { Log.i(tag, "mWifiManager.getWifiState() == WifiManager.WIFI_STATE_DISABLED"); return true; } } } return false; }
From source file:org.servDroid.server.service.ServerService.java
@Override public void onCreate() { super.onCreate(); wifiStateChangedReceiver = new BroadcastReceiver() { @Override//from w w w. ja v a 2s . co m 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;//w ww .jav a2s. c om 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 .jav a2s.c o 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; }/*from www . j av a 2s .c om*/ 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; }