List of usage examples for android.net.wifi WifiInfo getDetailedStateOf
public static DetailedState getDetailedStateOf(SupplicantState suppState)
From source file:Main.java
/** * Checks if is wifi.//from w w w . j av a 2 s. c o m * * @param ctx * the ctx * @return true, if is wifi */ public static boolean isWifi(final Context ctx) { WifiManager wm = (WifiManager) ctx.getSystemService(Context.WIFI_SERVICE); WifiInfo wi = wm.getConnectionInfo(); if (wi != null && (WifiInfo.getDetailedStateOf(wi.getSupplicantState()) == DetailedState.OBTAINING_IPADDR || WifiInfo.getDetailedStateOf(wi.getSupplicantState()) == DetailedState.CONNECTED)) { return true; } return false; }
From source file:com.ultrafunk.network_info.receiver.WifiStatusReceiver.java
@Override public void onReceive(Context context, Intent intent) { final String action = intent.getAction(); // Log.e(this.getClass().getSimpleName(), "onReceive(): " + action); updateWifiViews = true;/*w ww. ja va2s . c o m*/ wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); wifiState = wifiManager.getWifiState(); wifiInfo = wifiManager.getConnectionInfo(); if ((wifiState == WifiManager.WIFI_STATE_ENABLED) && (wifiInfo.getIpAddress() == 0)) detailedState = WifiInfo.getDetailedStateOf(wifiInfo.getSupplicantState()); if (WifiManager.NETWORK_STATE_CHANGED_ACTION.equals(action)) { if (isConnectionReady(intent)) { String securityString = WifiUtils.getSecurityString(context, wifiManager, wifiInfo.getBSSID()); NetworkStateService.setWifiSecurityString(securityString); detailsString = context.getString(R.string.security) + ": " + securityString; Intent serviceIntent = new Intent(context, NetworkStateService.class); serviceIntent.setAction(Constants.ACTION_WIFI_CONNECTED); context.startService(serviceIntent); } partiallyUpdateWidgets(context); } else if (WifiManager.WIFI_STATE_CHANGED_ACTION.equals(action) || Constants.ACTION_WIFI_SCANNING.equals(action)) { partiallyUpdateWidgets(context); } else if (Intent.ACTION_SCREEN_ON.equals(action) || Constants.ACTION_WIFI_LINK_SPEED.equals(action)) { if (isConnected()) { setDetailsString(context); partiallyUpdateWidgets(context); } } else if (Constants.ACTION_UPDATE_WIDGET.equals(action)) { if (isConnected()) setDetailsString(context); partiallyUpdateWidget(context, AppWidgetManager.getInstance(context), intent.getIntExtra(Constants.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID)); } }
From source file:eu.vranckaert.worktime.utils.network.NetworkUtil.java
/** * Checks if the device is connected to a WiFi network or not. * @param ctx The app-context.//from www . j a v a 2 s. c o m * @return {@link Boolean#TRUE} if the device is connected to a WiFi network, {@link Boolean#FALSE} otherwise. */ public static boolean isConnectedToWifi(Context ctx) { WifiManager wifiManager = (WifiManager) ctx.getSystemService(Context.WIFI_SERVICE); if (wifiManager != null) { SupplicantState state = wifiManager.getConnectionInfo().getSupplicantState(); if (state != null) { NetworkInfo.DetailedState detailedState = WifiInfo.getDetailedStateOf(state); if (detailedState != null) { if (detailedState == NetworkInfo.DetailedState.CONNECTED) { return true; } } } } return false; }
From source file:nacho.tfg.blepresencetracker.MyFirebaseInstanceIDService.java
/** * Persist token to third-party servers. * * Modify this method to associate the user's FCM InstanceID token with any server-side account * maintained by your application./*from w w w . ja v a2 s.co m*/ * * @param token The new token. */ private void sendRegistrationToServer(String token) { // Add custom implementation, as needed. Intent intent = new Intent(ACTION_SHOW_TOKEN); intent.putExtra("token", token); LocalBroadcastManager.getInstance(this).sendBroadcast(intent); AsyncTask<String, Void, Boolean> asyncTask = new AsyncTask<String, Void, Boolean>() { @Override protected void onPreExecute() { super.onPreExecute(); } @Override protected Boolean doInBackground(String... params) { String data = params[0]; String ip = "192.168.4.1"; int port = 7777; try { Socket socket = new Socket(ip, port); while (!socket.isConnected()) { } OutputStream out = socket.getOutputStream(); PrintWriter output = new PrintWriter(out); output.println(data); output.flush(); out.close(); output.close(); socket.close(); } catch (SocketException e) { e.printStackTrace(); return false; } catch (IOException e) { e.printStackTrace(); return false; } return true; } @Override protected void onPostExecute(Boolean result) { super.onPostExecute(result); if (result) { SharedPreferences settings = PreferenceManager .getDefaultSharedPreferences(MyFirebaseInstanceIDService.this); SharedPreferences.Editor editor = settings.edit(); editor.putBoolean(getString(R.string.registration_id_sent), true); editor.commit(); } else { SharedPreferences settings = PreferenceManager .getDefaultSharedPreferences(MyFirebaseInstanceIDService.this); SharedPreferences.Editor editor = settings.edit(); editor.putBoolean(getString(R.string.registration_id_sent), false); editor.commit(); } } }; // Change wifi network to "NodeMCU WiFi" String ssid = ""; WifiManager wifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE); WifiInfo wifiInfo = wifiManager.getConnectionInfo(); if (WifiInfo.getDetailedStateOf(wifiInfo.getSupplicantState()) == NetworkInfo.DetailedState.CONNECTED) { ssid = wifiInfo.getSSID(); } if (!ssid.equals("NodeMCU WiFi")) { Handler handler = new Handler(Looper.getMainLooper()); handler.post(new Runnable() { @Override public void run() { Toast.makeText(getApplicationContext(), getString(R.string.toast_connect_NodeMCU), Toast.LENGTH_LONG).show(); } }); } }
From source file:com.example.aaron.test.MyGLSurfaceView.java
public void tick() { antispam = antispam + 1;//from w ww .ja v a2 s .c o m count = 0; WifiInfo wifiInfo = getWifi(context1); NetworkInfo.DetailedState state = WifiInfo.getDetailedStateOf(wifiInfo.getSupplicantState()); mRenderer.textListSINFO.get(1).setText("Strength: " + wifiInfo.getRssi()); if (state == NetworkInfo.DetailedState.CONNECTED || state == NetworkInfo.DetailedState.OBTAINING_IPADDR) { mRenderer.textListSINFO.get(2).setText("Network: " + wifiInfo.getSSID()); } if (mRenderer.voronoiDeploymentToggle.active == true) { mRenderer.textListSINFO.get(3).setText("Deployment: Multi-agent Voronoi"); } else if (pFlag == 1) { mRenderer.textListSINFO.get(3).setText("Go to Goal"); } for (int i = 0; i < 50; i++) { if (tList[i].getState() == 1) { count++; if (count > 1) { mRenderer.textListARINFO.get(0).setText("Multiple Robots Selected"); mRenderer.textListARINFO.get(2).setText(" X:"); mRenderer.textListARINFO.get(3).setText(" Y:"); mRenderer.textListARINFO.get(4).setText(" Z:"); } else { mRenderer.textListARINFO.get(0).setText(tList[i].getIdentification()); mRenderer.textListARINFO.get(2).setText(" X:" + truncateDecimal(tList[i].getX(), 3)); mRenderer.textListARINFO.get(3).setText(" Y:" + truncateDecimal(tList[i].getY(), 3)); mRenderer.textListARINFO.get(4).setText(" Z:" + truncateDecimal(tList[i].getZ(), 3)); } } } if (count == 0) { mRenderer.textListARINFO.get(0).setText("No Robots Selected"); mRenderer.textListARINFO.get(2).setText(" X:"); mRenderer.textListARINFO.get(3).setText(" Y:"); mRenderer.textListARINFO.get(4).setText(" Z:"); } mRenderer.getUniqueVertices(); mRenderer.toMapPoints(); mRenderer.calculateAdjacencyMatrix(); mRenderer.calculateAdjacencyMatrixGoal(); if (!mRenderer.obstacleMapPoints.isEmpty()) { mRenderer.Dijkstra(); } }
From source file:ca.frozen.curlingtv.classes.Utils.java
public static String getWifiName() { String ssid = ""; WifiManager manager = (WifiManager) App.getContext().getSystemService(Context.WIFI_SERVICE); if (manager.isWifiEnabled()) { WifiInfo wifiInfo = manager.getConnectionInfo(); if (wifiInfo != null) { NetworkInfo.DetailedState state = WifiInfo.getDetailedStateOf(wifiInfo.getSupplicantState()); if (state == NetworkInfo.DetailedState.CONNECTED || state == NetworkInfo.DetailedState.OBTAINING_IPADDR) { ssid = wifiInfo.getSSID(); if (ssid == null) ssid = ""; ssid = ssid.replaceAll("^\"|\"$", ""); }/* w w w.j a v a 2s .c om*/ } } return ssid; }
From source file:at.alladin.rmbt.android.util.InformationCollector.java
private void getWiFiInfo() { initNetwork();//from w w w. j a v a 2s.c o m if (wifiManager != null) { final WifiInfo wifiInfo = wifiManager.getConnectionInfo(); fullInfo.setProperty("WIFI_SSID", String.valueOf(Helperfunctions.removeQuotationsInCurrentSSIDForJellyBean(wifiInfo.getSSID()))); /* * fullInfo.setProperty("WIFI_LINKSPEED", * String.valueOf(wifiInfo.getLinkSpeed())); */ fullInfo.setProperty("WIFI_BSSID", String.valueOf(wifiInfo.getBSSID())); fullInfo.setProperty("WIFI_NETWORK_ID", String.valueOf(wifiInfo.getNetworkId())); /* * fullInfo.setProperty("WIFI_RSSI", * String.valueOf(wifiInfo.getRssi())); */ final SupplicantState wifiState = wifiInfo.getSupplicantState(); fullInfo.setProperty("WIFI_SUPPLICANT_STATE", String.valueOf(wifiState.name())); final DetailedState wifiDetail = WifiInfo.getDetailedStateOf(wifiState); fullInfo.setProperty("WIFI_SUPPLICANT_STATE_DETAIL", String.valueOf(wifiDetail.name())); if (getNetwork() == NETWORK_WIFI) { final int rssi = wifiInfo.getRssi(); if (rssi != -1 && rssi >= ACCEPT_WIFI_RSSI_MIN) { int linkSpeed = wifiInfo.getLinkSpeed(); if (linkSpeed < 0) { linkSpeed = 0; } final SignalItem signalItem = SignalItem.getWifiSignalItem(linkSpeed, rssi); if (this.collectInformation) { signals.add(signalItem); } lastSignalItem.set(signalItem); signal.set(rssi); signalType.set(SINGAL_TYPE_WLAN); // Log.i(DEBUG_TAG, "Signals1: " + signals.toString()); } } } }
From source file:org.sipdroid.sipua.ui.Receiver.java
public static boolean isFast(int i) { WifiManager wm = (WifiManager) mContext.getSystemService(Context.WIFI_SERVICE); WifiInfo wi = wm.getConnectionInfo(); if (PreferenceManager.getDefaultSharedPreferences(mContext) .getString(org.sipdroid.sipua.ui.Settings.PREF_USERNAME + (i != 0 ? i : ""), "").equals("") || PreferenceManager.getDefaultSharedPreferences(mContext) .getString(org.sipdroid.sipua.ui.Settings.PREF_SERVER + (i != 0 ? i : ""), "").equals("")) return false; if (wi != null) { if (!Sipdroid.release) Log.i("SipUA:", "isFastWifi() " + WifiInfo.getDetailedStateOf(wi.getSupplicantState()) + " " + wi.getIpAddress()); if (wi.getIpAddress() != 0 && (WifiInfo.getDetailedStateOf(wi.getSupplicantState()) == DetailedState.OBTAINING_IPADDR || WifiInfo.getDetailedStateOf(wi.getSupplicantState()) == DetailedState.CONNECTED) || WifiInfo.getDetailedStateOf(wi.getSupplicantState()) == DetailedState.CONNECTING) { on_wlan = true;/*from w ww .j a va 2 s .co m*/ if (!on_vpn()) return PreferenceManager.getDefaultSharedPreferences(mContext).getBoolean( org.sipdroid.sipua.ui.Settings.PREF_WLAN + (i != 0 ? i : ""), org.sipdroid.sipua.ui.Settings.DEFAULT_WLAN); else return PreferenceManager.getDefaultSharedPreferences(mContext).getBoolean( org.sipdroid.sipua.ui.Settings.PREF_VPN + (i != 0 ? i : ""), org.sipdroid.sipua.ui.Settings.DEFAULT_VPN); } } on_wlan = false; return isFastGSM(i); }
From source file:com.csipsimple.service.SipService.java
/** * Ask to take the control of the wifi and the partial wake lock if * configured/* ww w .ja va 2 s .c om*/ */ private synchronized void acquireResources() { if (holdResources) { return; } // Add a wake lock for CPU if necessary if (prefsWrapper.getPreferenceBooleanValue(SipConfigManager.USE_PARTIAL_WAKE_LOCK)) { PowerManager pman = (PowerManager) getSystemService(Context.POWER_SERVICE); if (wakeLock == null) { wakeLock = pman.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "com.csipsimple.SipService"); wakeLock.setReferenceCounted(false); } // Extra check if set reference counted is false ??? if (!wakeLock.isHeld()) { wakeLock.acquire(); } } // Add a lock for WIFI if necessary WifiManager wman = (WifiManager) getSystemService(Context.WIFI_SERVICE); if (wifiLock == null) { int mode = WifiManager.WIFI_MODE_FULL; if (Compatibility.isCompatible(9) && prefsWrapper.getPreferenceBooleanValue(SipConfigManager.LOCK_WIFI_PERFS)) { mode = 0x3; // WIFI_MODE_FULL_HIGH_PERF } wifiLock = wman.createWifiLock(mode, "com.csipsimple.SipService"); wifiLock.setReferenceCounted(false); } if (prefsWrapper.getPreferenceBooleanValue(SipConfigManager.LOCK_WIFI) && !wifiLock.isHeld()) { WifiInfo winfo = wman.getConnectionInfo(); if (winfo != null) { DetailedState dstate = WifiInfo.getDetailedStateOf(winfo.getSupplicantState()); // We assume that if obtaining ip addr, we are almost connected // so can keep wifi lock if (dstate == DetailedState.OBTAINING_IPADDR || dstate == DetailedState.CONNECTED) { if (!wifiLock.isHeld()) { wifiLock.acquire(); } } } } holdResources = true; }
From source file:ua.mkh.settings.full.MainActivity.java
private void ButtonTextWifi() { TextView textwifi = (TextView) findViewById(R.id.textwifi); if (wifi.isWifiEnabled()) { textwifi.setText(R.string.on);//from w ww . java2s. co m } else { textwifi.setText(R.string.off); } WifiManager manager = (WifiManager) this.getSystemService(Context.WIFI_SERVICE); if (manager.isWifiEnabled()) { WifiInfo wifiInfo = manager.getConnectionInfo(); if (wifiInfo != null) { DetailedState state = WifiInfo.getDetailedStateOf(wifiInfo.getSupplicantState()); if (state == DetailedState.CONNECTED || state == DetailedState.OBTAINING_IPADDR) { String wi = wifiInfo.getSSID().replace('"', ' '); textwifi.setText(wi); } } } }