Java Code Examples for android.net.wifi.WifiManager#WIFI_STATE_UNKNOWN
The following examples show how to use
android.net.wifi.WifiManager#WIFI_STATE_UNKNOWN .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Wifi.java From batteryhub with Apache License 2.0 | 6 votes |
/** * Get Wifi state. * * @param context The Context * @return Wifi state constant, an int value */ public static String getState(Context context) { WifiManager manager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); int wifiState = manager.getWifiState(); switch (wifiState) { case WifiManager.WIFI_STATE_DISABLED: return WIFI_STATE_DISABLED; case WifiManager.WIFI_STATE_DISABLING: return WIFI_STATE_DISABLING; case WifiManager.WIFI_STATE_ENABLED: return WIFI_STATE_ENABLED; case WifiManager.WIFI_STATE_ENABLING: return WIFI_STATE_ENABLING; case WifiManager.WIFI_STATE_UNKNOWN: return WIFI_STATE_UNKNOWN; default: return WIFI_STATE_UNKNOWN; } }
Example 2
Source File: DLNAService.java From AndroidVideoPlayer with GNU General Public License v2.0 | 6 votes |
@Override public void onReceive(Context c, Intent intent) { Bundle bundle = intent.getExtras(); int statusInt = bundle.getInt("wifi_state"); switch (statusInt) { case WifiManager.WIFI_STATE_UNKNOWN: break; case WifiManager.WIFI_STATE_ENABLING: break; case WifiManager.WIFI_STATE_ENABLED: LogUtil.e(TAG, "wifi enable"); startThread(); break; case WifiManager.WIFI_STATE_DISABLING: break; case WifiManager.WIFI_STATE_DISABLED: LogUtil.e(TAG, "wifi disabled"); break; default: break; } }
Example 3
Source File: SwapWorkflowActivity.java From fdroidclient with GNU General Public License v3.0 | 6 votes |
@Override public void onReceive(Context context, Intent intent) { setUpFromWifi(); int wifiStatus = -1; TextView textWifiVisible = container.findViewById(R.id.wifi_visible); if (textWifiVisible != null) { intent.getIntExtra(WifiStateChangeService.EXTRA_STATUS, -1); } switch (wifiStatus) { case WifiManager.WIFI_STATE_ENABLING: textWifiVisible.setText(R.string.swap_setting_up_wifi); break; case WifiManager.WIFI_STATE_ENABLED: textWifiVisible.setText(R.string.swap_not_visible_wifi); break; case WifiManager.WIFI_STATE_DISABLING: case WifiManager.WIFI_STATE_DISABLED: textWifiVisible.setText(R.string.swap_stopping_wifi); break; case WifiManager.WIFI_STATE_UNKNOWN: break; } }
Example 4
Source File: WifiStateChangeService.java From fdroidclient with GNU General Public License v3.0 | 6 votes |
private String printWifiState(int wifiState) { switch (wifiState) { case WifiManager.WIFI_STATE_DISABLED: return "WIFI_STATE_DISABLED"; case WifiManager.WIFI_STATE_DISABLING: return "WIFI_STATE_DISABLING"; case WifiManager.WIFI_STATE_ENABLING: return "WIFI_STATE_ENABLING"; case WifiManager.WIFI_STATE_ENABLED: return "WIFI_STATE_ENABLED"; case WifiManager.WIFI_STATE_UNKNOWN: return "WIFI_STATE_UNKNOWN"; case Integer.MIN_VALUE: return "previous value unset"; default: return "~not mapped~"; } }
Example 5
Source File: WifiUtils.java From DevUtils with Apache License 2.0 | 5 votes |
/** * 获取当前 Wifi 连接状态 * @return Wifi 连接状态 */ @SuppressLint("MissingPermission") public int getWifiState() { // WifiManager.WIFI_STATE_ENABLED: // 已打开 // WifiManager.WIFI_STATE_ENABLING: // 正在打开 // WifiManager.WIFI_STATE_DISABLED: // 已关闭 // WifiManager.WIFI_STATE_DISABLING: // 正在关闭 // WifiManager.WIFI_STATE_UNKNOWN: // 未知 try { return mWifiManager.getWifiState(); } catch (Exception e) { LogPrintUtils.eTag(TAG, e, "getWifiState"); } return WifiManager.WIFI_STATE_UNKNOWN; }
Example 6
Source File: NetworkConnectivityManager.java From android-project-wo2b with Apache License 2.0 | 5 votes |
/** * * @param context * @param intent * @param action */ public void wifiStateChangedAction(Context context, Intent intent, String action) { if (WifiManager.WIFI_STATE_CHANGED_ACTION.equals(action)) { // 在此监听wifi有无 int wifiState = intent.getIntExtra(WifiManager.EXTRA_WIFI_STATE, 0); switch (wifiState) { case WifiManager.WIFI_STATE_DISABLED: { Toast.makeText(context, "WIFI_STATE_DISABLED", Toast.LENGTH_LONG).show(); break; } case WifiManager.WIFI_STATE_DISABLING: { Toast.makeText(context, "WIFI_STATE_DISABLING", Toast.LENGTH_LONG).show(); break; } case WifiManager.WIFI_STATE_ENABLED: { Toast.makeText(context, "WIFI_STATE_ENABLED", Toast.LENGTH_LONG).show(); break; } case WifiManager.WIFI_STATE_ENABLING: { Toast.makeText(context, "WIFI_STATE_ENABLING", Toast.LENGTH_LONG).show(); break; } case WifiManager.WIFI_STATE_UNKNOWN: { Toast.makeText(context, "WIFI_STATE_UNKNOWN", Toast.LENGTH_LONG).show(); break; } } } }
Example 7
Source File: WifiStateChangeService.java From fdroidclient with GNU General Public License v3.0 | 5 votes |
@Override protected void onHandleIntent(Intent intent) { android.os.Process.setThreadPriority(android.os.Process.THREAD_PRIORITY_LOWEST); if (intent == null) { Utils.debugLog(TAG, "received null Intent, ignoring"); return; } Utils.debugLog(TAG, "WiFi change service started."); NetworkInfo ni = intent.getParcelableExtra(WifiManager.EXTRA_NETWORK_INFO); wifiManager = (WifiManager) getApplicationContext().getSystemService(WIFI_SERVICE); wifiState = wifiManager.getWifiState(); Utils.debugLog(TAG, "ni == " + ni + " wifiState == " + printWifiState(wifiState)); if (ni == null || ni.getState() == NetworkInfo.State.CONNECTED || ni.getState() == NetworkInfo.State.DISCONNECTED) { if (previousWifiState != wifiState && (wifiState == WifiManager.WIFI_STATE_ENABLED || wifiState == WifiManager.WIFI_STATE_DISABLING // might be switching to hotspot || wifiState == WifiManager.WIFI_STATE_DISABLED // might be hotspot || wifiState == WifiManager.WIFI_STATE_UNKNOWN)) { // might be hotspot if (wifiInfoThread != null) { wifiInfoThread.interrupt(); } wifiInfoThread = new WifiInfoThread(); wifiInfoThread.start(); } if (Build.VERSION.SDK_INT < 21 && wifiState == WifiManager.WIFI_STATE_ENABLED) { UpdateService.scheduleIfStillOnWifi(this); } } }
Example 8
Source File: WifiStateChangeReceiver.java From Smartlab with Apache License 2.0 | 5 votes |
@Override public void onReceive(Context context, Intent intent) { abortBroadcast(); WifiManager wifiManager = (WifiManager) context .getSystemService(Context.WIFI_SERVICE); switch (wifiManager.getWifiState()) { case WifiManager.WIFI_STATE_DISABLED: Toast.makeText(context, "WIFI_STATE_DISABLED", Toast.LENGTH_LONG) .show(); break; case WifiManager.WIFI_STATE_ENABLED: Toast.makeText(context, "WIFI_STATE_ENABLED", Toast.LENGTH_LONG) .show(); break; case WifiManager.WIFI_STATE_DISABLING: Toast.makeText(context, "WIFI_STATE_DISABLING", Toast.LENGTH_LONG) .show(); break; case WifiManager.WIFI_STATE_ENABLING: Toast.makeText(context, "WIFI_STATE_ENABLING", Toast.LENGTH_LONG) .show(); break; case WifiManager.WIFI_STATE_UNKNOWN: Toast.makeText(context, "WIFI_STATE_UNKNOWN", Toast.LENGTH_LONG) .show(); break; } }
Example 9
Source File: NetworkConnectChangedReceiver.java From AndroidDemo with MIT License | 4 votes |
@Override public void onReceive(Context context, Intent intent) {// 这个监听wifi的打开与关闭,与wifi的连接无关 if (WifiManager.WIFI_STATE_CHANGED_ACTION.equals(intent.getAction())) { int wifiState = intent.getIntExtra(WifiManager.EXTRA_WIFI_STATE, 0); Log.e(TAG0, "WIFI状态:" + wifiState); switch (wifiState) { case WifiManager.WIFI_STATE_DISABLED: //APP.getInstance().setEnablaWifi(false); Log.e(TAG0,"WIFI_STATE_DISABLED" ); break; case WifiManager.WIFI_STATE_DISABLING: Log.e(TAG0,"WIFI_STATE_DISABLING" ); break; case WifiManager.WIFI_STATE_ENABLING: Log.e(TAG0,"WIFI_STATE_ENABLING" ); break; case WifiManager.WIFI_STATE_ENABLED: //APP.getInstance().setEnablaWifi(true); Log.e(TAG0,"WIFI_STATE_ENABLED"); break; case WifiManager.WIFI_STATE_UNKNOWN: Log.e(TAG0,"WIFI_STATE_UNKNOWN" ); break; default: break; } } // 这个监听wifi的连接状态即是否连上了一个有效无线路由,当上边广播的状态是WifiManager // .WIFI_STATE_DISABLING,和WIFI_STATE_DISABLED的时候,根本不会接到这个广播。 // 在上边广播接到广播是WifiManager.WIFI_STATE_ENABLED状态的同时也会接到这个广播, // 当然刚打开wifi肯定还没有连接到有效的无线 if (WifiManager.NETWORK_STATE_CHANGED_ACTION.equals(intent.getAction())) { Parcelable parcelableExtra = intent.getParcelableExtra(WifiManager.EXTRA_NETWORK_INFO); if (null != parcelableExtra) { NetworkInfo networkInfo = (NetworkInfo) parcelableExtra; NetworkInfo.State state = networkInfo.getState(); boolean isConnected = state == NetworkInfo.State.CONNECTED;// 当然,这边可以更精确的确定状态 Log.e(TAG1, "WIFI连接状态:" + isConnected); if (isConnected) { //APP.getInstance().setWifi(true); } else { // APP.getInstance().setWifi(false); } } } // 这个监听网络连接的设置,包括wifi和移动数据的打开和关闭。. // 最好用的还是这个监听。wifi如果打开,关闭,以及连接上可用的连接都会接到监听。 // 这个广播的最大弊端是比上边两个广播的反应要慢,如果只是要监听wifi,觉得还是用上边两个配合比较合适。 if (ConnectivityManager.CONNECTIVITY_ACTION.equals(intent.getAction())) { ConnectivityManager manager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); Log.i(TAG2, "CONNECTIVITY_ACTION"); string = "\n您的手机当前网络状态是:\n\n"; NetworkInfo activeNetwork = manager.getActiveNetworkInfo(); if (activeNetwork != null) { // connected to the internet if (activeNetwork.isConnected()) { if (activeNetwork.getType() == ConnectivityManager.TYPE_WIFI) { // connected to wifi string += "当前WiFi连接可用 "; } else if (activeNetwork.getType() == ConnectivityManager.TYPE_MOBILE) { // connected to the mobile provider's data plan string += "当前移动网络连接可用 "; } } else { string += "当前没有网络连接,请确保你已经打开网络 "; } string += "\n类型名:" + activeNetwork.getTypeName()+ "\n子类型名:" + activeNetwork.getSubtypeName()+ "\n状态:" + activeNetwork.getState()+ "\n详细状态:" + activeNetwork.getDetailedState().name()+ "\n额外状态:" + activeNetwork.getExtraInfo()+ "\n类型:" + activeNetwork.getType(); } else { // not connected to the internet string += "当前没有网络连接,请确保你已经打开网络 "; } Log.e("String:",string); brInteraction.setText(string); } }
Example 10
Source File: WifiReceiver.java From NetworkGhost with GNU General Public License v2.0 | 4 votes |
@Override public void onReceive(Context context, Intent intent) { int wifiState = intent.getIntExtra(WifiManager.EXTRA_WIFI_STATE, WifiManager.WIFI_STATE_UNKNOWN); String wifiStateText = "No State"; String action = intent.getAction(); if (action.equals(WifiManager.NETWORK_STATE_CHANGED_ACTION)) { WifiManager manager = (WifiManager) context .getSystemService(Context.WIFI_SERVICE); NetworkInfo networkInfo = intent .getParcelableExtra(WifiManager.EXTRA_NETWORK_INFO); NetworkInfo.State state = networkInfo.getState(); if (state == NetworkInfo.State.DISCONNECTED) { if (manager.isWifiEnabled()) { doUpdate(context); wifiStateText = "WIFI_STATE_DISCONNECTED"; } } } switch (wifiState) { case WifiManager.WIFI_STATE_DISABLING: wifiStateText = "WIFI_STATE_DISABLING"; break; case WifiManager.WIFI_STATE_DISABLED: wifiStateText = "WIFI_STATE_DISABLED"; break; case WifiManager.WIFI_STATE_ENABLING: wifiStateText = "WIFI_STATE_ENABLING"; break; case WifiManager.WIFI_STATE_ENABLED: wifiStateText = "WIFI_STATE_ENABLED"; if (state == 1) state--; else doUpdate(context); break; case WifiManager.WIFI_STATE_UNKNOWN: wifiStateText = "WIFI_STATE_UNKNOWN"; break; default: break; } System.out.println("WIFI_recv: " + wifiStateText); }