List of usage examples for android.net.wifi WifiManager WIFI_STATE_ENABLED
int WIFI_STATE_ENABLED
To view the source code for android.net.wifi WifiManager WIFI_STATE_ENABLED.
Click Source Link
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);// w w w . j a va 2s . 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:com.prey.events.factories.EventFactory.java
public static Event getEvent(Context ctx, Intent intent) { String message = "getEvent[" + intent.getAction() + "]"; PreyLogger.d(message);//from w ww . ja v a 2 s . c o 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:org.exobel.routerkeygen.ui.NetworksListActivity.java
@TargetApi(Build.VERSION_CODES.JELLY_BEAN) @Override/*from ww w .ja va 2 s . c om*/ public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_networks_list); networkListFragment = ((NetworksListFragment) getFragmentManager() .findFragmentById(R.id.frag_networks_list)); if (findViewById(R.id.keygen_fragment) != null) { mTwoPane = true; networkListFragment.setActivateOnItemClick(true); } wifi = (WifiManager) getSystemService(Context.WIFI_SERVICE); wifiState = wifi.getWifiState() == WifiManager.WIFI_STATE_ENABLED || wifi.getWifiState() == WifiManager.WIFI_STATE_ENABLING; scanFinished = new WifiScanReceiver(wifi, networkListFragment, this); stateChanged = new WifiStateReceiver(wifi, networkListFragment); final SharedPreferences mPrefs = PreferenceManager.getDefaultSharedPreferences(this); welcomeScreenShown = mPrefs.getBoolean(Preferences.VERSION, false); final long timePassed = System.currentTimeMillis() - mPrefs.getLong(LAST_DIALOG_TIME, 0); if (!welcomeScreenShown || (timePassed > DateUtils.WEEK_IN_MILLIS)) { final SharedPreferences.Editor editor = mPrefs.edit(); editor.putBoolean(Preferences.VERSION, true); editor.putLong(LAST_DIALOG_TIME, System.currentTimeMillis()); editor.apply(); // Checking for updates every week if (BuildConfig.APPLICATION_ID.equals("org.exobel.routerkeygen")) { startService(new Intent(getApplicationContext(), UpdateCheckerService.class)); } // } mSwipeRefreshLayout = (SwipeRefreshLayout) findViewById(R.id.swiperefresh); mSwipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() { @Override public void onRefresh() { scan(); } }); mSwipeRefreshLayout.setColorSchemeResources(R.color.accent); }
From source file:com.ultrafunk.network_info.receiver.WifiStatusReceiver.java
private boolean isConnected() { return ((wifiState == WifiManager.WIFI_STATE_ENABLED) && (wifiInfo.getIpAddress() != 0)); }
From source file:org.deviceconnect.android.deviceplugin.hvcc2w.setting.fragment.HVCC2WPairingFragment.java
/** * Check Wifi.// w w w . j av a 2s . c om */ private void searchWifi() { final WifiManager wifiManager = getWifiManager(); if (wifiManager.getWifiState() == WifiManager.WIFI_STATE_ENABLED) { mReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { List<ScanResult> results = wifiManager.getScanResults(); if (results.size() == 0) { return; } mSSID.setText(results.get(0).SSID); } }; getActivity().registerReceiver(mReceiver, new IntentFilter(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION)); } wifiManager.startScan(); }
From source file:org.openremote.android.console.net.ORNetworkCheck.java
/** * Detects the current WiFi status.//ww w. ja v a2 s . c o m * * @param ctx global Android application context * * @return true if WiFi is available, false otherwise */ private static boolean canReachWifiNetwork(Context ctx) { WifiManager wifiManager = (WifiManager) ctx.getSystemService(Context.WIFI_SERVICE); ConnectivityManager connectivityManager = (ConnectivityManager) ctx .getSystemService(Context.CONNECTIVITY_SERVICE); if (!wifiManager.isWifiEnabled() || wifiManager.getWifiState() != WifiManager.WIFI_STATE_ENABLED) { Log.i(LOG_CATEGORY, "WiFi not enabled or WiFi network not detected."); return false; } NetworkInfo wifiNetworkInfo = connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI); if (!wifiNetworkInfo.isAvailable()) { Log.i(LOG_CATEGORY, "Wifi network detected but wasn't available."); return false; } else { return true; } }
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())); }// w ww. ja va 2 s . c om } 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; }// w ww . j a va 2 s . 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:com.lgallardo.qbittorrentclient.NotifierService.java
protected void getSettings() { // Preferences stuff sharedPrefs = PreferenceManager.getDefaultSharedPreferences(context); builderPrefs = new StringBuilder(); builderPrefs.append("\n" + sharedPrefs.getString("language", "NULL")); // Get values from preferences currentServer = Integer.parseInt(sharedPrefs.getString("currentServer", "1")); hostname = sharedPrefs.getString("hostname", ""); subfolder = sharedPrefs.getString("subfolder", ""); protocol = sharedPrefs.getString("protocol", "NULL"); // If user leave the field empty, set 8080 port try {/*from ww w. ja v a 2 s . c o m*/ port = Integer.parseInt(sharedPrefs.getString("port", "8080")); } catch (NumberFormatException e) { port = 8080; } username = sharedPrefs.getString("username", "NULL"); password = sharedPrefs.getString("password", "NULL"); https = sharedPrefs.getBoolean("https", false); // Check https if (https) { protocol = "https"; } else { protocol = "http"; } // Get connection and data timeouts try { connection_timeout = Integer.parseInt(sharedPrefs.getString("connection_timeout", "10")); } catch (NumberFormatException e) { connection_timeout = 10; } try { data_timeout = Integer.parseInt(sharedPrefs.getString("data_timeout", "20")); } catch (NumberFormatException e) { data_timeout = 20; } qb_version = sharedPrefs.getString("qb_version", "3.2.x"); cookie = sharedPrefs.getString("qbCookie2", null); // Get last state lastState = sharedPrefs.getString("lastState", null); // Notifications enable_notifications = sharedPrefs.getBoolean("enable_notifications", false); completed_hashes = sharedPrefs.getString("completed_hashes" + currentServer, ""); // Get local SSID properties ssid = sharedPrefs.getString("ssid", ""); local_hostname = sharedPrefs.getString("local_hostname", null); // If user leave the field empty, set 8080 port try { local_port = Integer.parseInt(sharedPrefs.getString("local_port", "-1")); } catch (NumberFormatException e) { local_port = -1; } // Set SSI and local hostname and port if (ssid != null && !ssid.equals("")) { // Get SSID if WiFi WifiManager wifiMgr = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); WifiInfo wifiInfo = wifiMgr.getConnectionInfo(); String wifiSSID = wifiInfo.getSSID(); // Log.d("Debug", "NotifierService - WiFi SSID: " + wifiSSID); // Log.d("Debug", "NotifierService - SSID: " + ssid); if (wifiSSID.equals("\"" + ssid + "\"") && wifiMgr.getWifiState() == WifiManager.WIFI_STATE_ENABLED) { if (local_hostname != null && !local_hostname.equals("")) { hostname = local_hostname; } if (local_port != -1) { port = local_port; } // Log.d("Debug", "NotifierService - hostname: " + hostname); // Log.d("Debug", "NotifierService - port: " + port); // Log.d("Debug", "NotifierService - local_hostname: " + local_hostname); // Log.d("Debug", "NotifierService - local_port: " + local_port); } } // Get keystore for self-signed certificate keystore_path = sharedPrefs.getString("keystore_path" + currentServer, ""); keystore_password = sharedPrefs.getString("keystore_password" + currentServer, ""); }
From source file:org.servDroid.server.service.ServerService.java
@Override public void onCreate() { super.onCreate(); wifiStateChangedReceiver = new BroadcastReceiver() { @Override/*from w w w. j a v a 2s.c o 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)); }