List of usage examples for android.net.wifi WifiInfo getSSID
public String getSSID()
From source file:org.universAAL.android.services.MiddlewareService.java
/** * Check what is the current connection status of WiFi. * /*w ww .ja v a 2 s .c o m*/ * @return Constant representing the status. */ private int checkWifi() { // if (isWifiOn()) { WifiManager wifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE); WifiInfo wifiInfo = wifiManager.getConnectionInfo(); if (wifiInfo.getNetworkId() == -1) { //No network actually Log.i(TAG, "WIFI CHECK: Wifi is not on"); return AppConstants.WIFI_OFF; } String networkId = wifiInfo.getSSID(); String home = PreferenceManager.getDefaultSharedPreferences(this).getString(AppConstants.MY_WIFI, AppConstants.NO_WIFI); Log.i(TAG, "WIFI CHECK: Evaluating: " + networkId); if (home.equals(AppConstants.NO_WIFI)) { Log.i(TAG, "WIFI CHECK: We still do not have a home wifi, maybe this one will be?"); return AppConstants.WIFI_NOTSET; } else if (networkId.equals(home)) { Log.i(TAG, "WIFI CHECK: We have a home wifi, and we are in it!"); return AppConstants.WIFI_HOME; } else { Log.i(TAG, "WIFI CHECK: We have a home wifi, but it is not this one. If you want it to be, clear app data"); return AppConstants.WIFI_STRANGER; } // } // Log.i(TAG, "WIFI CHECK: Wifi is not on"); // return AppConstants.WIFI_OFF; }
From source file:ac.robinson.bettertogether.hotspot.HotspotManagerService.java
private void finishConnectingWifiHotspot(@NonNull ConnectionOptions connectionOptions) { // set up new network - *must* be surrounded by " (see: https://stackoverflow.com/questions/2140133/) Log.d(TAG, "Connecting to Wifi network " + connectionOptions.mName); WifiConfiguration wifiConfiguration = new WifiConfiguration(); WifiUtils.setConfigurationAttributes(wifiConfiguration, "\"" + connectionOptions.mName + "\"", "\"" + connectionOptions.mPassword + "\""); int savedNetworkId = WifiUtils.getWifiNetworkId(mWifiManager, wifiConfiguration.SSID); if (savedNetworkId >= 0) { Log.d(TAG, "Found saved Wifi network id"); mHotspotId = savedNetworkId;/*from w w w . j av a 2 s . c om*/ } else { Log.d(TAG, "Adding Wifi network"); mHotspotId = mWifiManager.addNetwork(wifiConfiguration); // mWifiManager.saveConfiguration(); // can change network IDs(!) - not really needed, so disabled if (mHotspotId < 0) { Log.d(TAG, "Couldn't add Wifi network"); mWifiConnectionErrorCount += 1; retryWifiConnection(); return; } } // if we're auto-connected to a previous network (unlikely!), continue straight away; if not, reconnect WifiInfo currentConnection = mWifiManager.getConnectionInfo(); if (currentConnection != null && wifiConfiguration.SSID.equals(currentConnection.getSSID())) { Log.d(TAG, "Continuing with current Wifi connection"); connectWifiClient(connectionOptions.mIPAddress, connectionOptions.mPort); } else { Log.d(TAG, "Enabling Wifi network"); mWifiManager.disconnect(); if (!mWifiManager.enableNetwork(mHotspotId, true)) { // connect to our network - handle connection in receiver Log.d(TAG, "Couldn't enable Wifi network"); mWifiConnectionErrorCount += 1; retryWifiConnection(); } else { Log.d(TAG, "Wifi network enabled"); mWifiManager.reconnect(); setWifiErrorTimeout(); } } }
From source file:at.alladin.rmbt.android.util.InformationCollector.java
private void getWiFiInfo() { initNetwork();/*from ww w . j av a 2 s . 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:com.prey.PreyPhone.java
private void updateWifi() { wifi = new Wifi(); try {//from w w w . ja v a2 s . c om WifiManager wifiMgr = (WifiManager) ctx.getSystemService(Context.WIFI_SERVICE); WifiInfo wifiInfo = wifiMgr.getConnectionInfo(); wifi.setWifiEnabled(wifiMgr.isWifiEnabled()); int ipAddress = wifiInfo.getIpAddress(); wifi.setIpAddress(formatterIp(ipAddress)); wifi.setMacAddress(wifiInfo.getMacAddress()); DhcpInfo dhcpInfo = wifiMgr.getDhcpInfo(); wifi.setNetmask(formatterIp(dhcpInfo.netmask)); wifi.setGatewayIp(formatterIp(dhcpInfo.serverAddress)); if (ipAddress != 0) { wifi.setInterfaceType("Wireless"); } else { if (PreyConnectivityManager.getInstance(ctx).isMobileConnected()) { wifi.setInterfaceType("Mobile"); } else { wifi.setInterfaceType(""); } } wifi.setName("eth0"); String ssid = wifiInfo.getSSID(); try { ssid = ssid.replaceAll("\"", ""); } catch (Exception e) { } wifi.setSsid(ssid); for (int i = 0; listWifi != null && i < listWifi.size(); i++) { Wifi _wifi = listWifi.get(i); ssid = _wifi.getSsid(); try { ssid = ssid.replaceAll("\"", ""); } catch (Exception e) { } if (ssid.equals(wifi.getSsid())) { wifi.setSecurity(_wifi.getSecurity()); wifi.setSignalStrength(_wifi.getSignalStrength()); wifi.setChannel(_wifi.getChannel()); break; } } } catch (Exception e) { } }
From source file:org.restcomm.app.qoslib.Utils.QosInfo.java
private WifiConfiguration getWifiConfig() { WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); WifiInfo wifiInfo = wifiManager.getConnectionInfo(); WifiConfiguration activeConfig = null; if (wifiManager.getConfiguredNetworks() == null) return null; for (WifiConfiguration conn : wifiManager.getConfiguredNetworks()) { if ((conn.BSSID != null && conn.BSSID.equals(wifiInfo.getBSSID())) || (conn.SSID != null && conn.SSID.equals(wifiInfo.getSSID()))) { activeConfig = conn;/*from w ww.ja va2s .c o m*/ break; } } if (activeConfig != null) { return activeConfig; } return null; }
From source file:com.example.aaron.test.MyGLSurfaceView.java
public void tick() { antispam = antispam + 1;/*from w w w. j ava2 s.com*/ 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:org.restcomm.app.qoslib.Services.Events.EventManager.java
public WifiConfiguration getWifiConfig() { WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); WifiInfo wifiInfo = wifiManager.getConnectionInfo(); WifiConfiguration activeConfig = null; if (wifiManager.getConfiguredNetworks() == null) return null; for (WifiConfiguration conn : wifiManager.getConfiguredNetworks()) { if ((conn.BSSID != null && conn.BSSID.equals(wifiInfo.getBSSID())) || (conn.SSID != null && conn.SSID.equals(wifiInfo.getSSID()))) { activeConfig = conn;/*from www. j a v a 2 s . c o m*/ break; } } if (activeConfig != null) { return activeConfig; } return null; }
From source file:com.newsrob.EntryManager.java
boolean isOnWiFi() { if (connectivityManager == null) connectivityManager = (ConnectivityManager) ctx.getSystemService(Context.CONNECTIVITY_SERVICE); if (connectivityManager == null) { PL.log("EntryManager. Wasn't able to get CONNECTIVITY_SERVICE.", ctx); WifiManager wifiManager = (WifiManager) ctx.getSystemService(Context.WIFI_SERVICE); WifiInfo wifiInfo = wifiManager.getConnectionInfo(); if (wifiInfo != null) PL.log("WiFi Info=" + wifiInfo + " SSID=" + wifiInfo.getSSID(), ctx); return false; }// www. j a v a 2s. c om final NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo(); if (networkInfo == null) { PL.log("EntryManager. Wasn't able to get Network Info.", ctx); return false; } if (ConnectivityManager.TYPE_WIFI != networkInfo.getType()) { PL.log("EntryManager. Network Info Type was not WiFi, but " + networkInfo.getType() + ".", ctx); return false; } return true; }
From source file:org.sipdroid.sipua.ui.Receiver.java
@Override public void onReceive(Context context, Intent intent) { String intentAction = intent.getAction(); if (!Sipdroid.on(context)) return;/*from w w w .j a va 2s .c om*/ if (!Sipdroid.release) Log.i("SipUA:", intentAction); if (mContext == null) mContext = context; if (intentAction.equals(Intent.ACTION_BOOT_COMPLETED)) { on_vpn(false); engine(context).register(); } else if (intentAction.equals(ConnectivityManager.CONNECTIVITY_ACTION) || intentAction.equals(ACTION_EXTERNAL_APPLICATIONS_AVAILABLE) || intentAction.equals(ACTION_EXTERNAL_APPLICATIONS_UNAVAILABLE) || intentAction.equals(Intent.ACTION_PACKAGE_REPLACED)) { engine(context).register(); } else if (intentAction.equals(ACTION_VPN_CONNECTIVITY) && intent.hasExtra("connection_state")) { String state = intent.getSerializableExtra("connection_state").toString(); if (state != null && on_vpn() != state.equals("CONNECTED")) { on_vpn(state.equals("CONNECTED")); for (SipProvider sip_provider : engine(context).sip_providers) if (sip_provider != null) sip_provider.haltConnections(); engine(context).register(); } } else if (intentAction.equals(ACTION_DATA_STATE_CHANGED)) { engine(context).registerMore(); } else if (intentAction.equals(ACTION_PHONE_STATE_CHANGED) && !intent.getBooleanExtra(context.getString(R.string.app_name), false)) { stopRingtone(); pstn_state = intent.getStringExtra("state"); pstn_time = SystemClock.elapsedRealtime(); if (pstn_state.equals("IDLE") && call_state != UserAgent.UA_STATE_IDLE) broadcastCallStateChanged(null, null); if (!pstn_state.equals("IDLE") && call_state == UserAgent.UA_STATE_INCALL) mHandler.sendEmptyMessageDelayed(MSG_HOLD, 5000); else if (!pstn_state.equals("IDLE") && (call_state == UserAgent.UA_STATE_INCOMING_CALL || call_state == UserAgent.UA_STATE_OUTGOING_CALL)) mHandler.sendEmptyMessageDelayed(MSG_HANGUP, 5000); else if (pstn_state.equals("IDLE")) { mHandler.removeMessages(MSG_HOLD); mHandler.removeMessages(MSG_HANGUP); if (call_state == UserAgent.UA_STATE_HOLD) mHandler.sendEmptyMessageDelayed(MSG_HOLD, 1000); } } else if (intentAction.equals(ACTION_DOCK_EVENT)) { docked = intent.getIntExtra(EXTRA_DOCK_STATE, -1) & 7; if (call_state == UserAgent.UA_STATE_INCALL) engine(mContext).speaker(speakermode()); } else if (intentAction.equals(ACTION_SCO_AUDIO_STATE_CHANGED)) { bluetooth = intent.getIntExtra(EXTRA_SCO_AUDIO_STATE, -1); progress(); RtpStreamSender.changed = true; } else if (intentAction.equals(Intent.ACTION_HEADSET_PLUG)) { headset = intent.getIntExtra("state", -1); if (call_state == UserAgent.UA_STATE_INCALL) engine(mContext).speaker(speakermode()); } else if (intentAction.equals(Intent.ACTION_SCREEN_ON)) { if (!PreferenceManager.getDefaultSharedPreferences(mContext).getBoolean( org.sipdroid.sipua.ui.Settings.PREF_OWNWIFI, org.sipdroid.sipua.ui.Settings.DEFAULT_OWNWIFI)) alarm(0, OwnWifi.class); } else if (intentAction.equals(Intent.ACTION_USER_PRESENT)) { mHandler.sendEmptyMessageDelayed(MSG_ENABLE, 3000); } else if (intentAction.equals(Intent.ACTION_SCREEN_OFF)) { if (PreferenceManager.getDefaultSharedPreferences(mContext).getBoolean( org.sipdroid.sipua.ui.Settings.PREF_OWNWIFI, org.sipdroid.sipua.ui.Settings.DEFAULT_OWNWIFI)) { WifiManager wm = (WifiManager) mContext.getSystemService(Context.WIFI_SERVICE); WifiInfo wi = wm.getConnectionInfo(); if (wm.getWifiState() != WifiManager.WIFI_STATE_ENABLED || wi == null || wi.getSupplicantState() != SupplicantState.COMPLETED || wi.getIpAddress() == 0) alarm(2 * 60, OwnWifi.class); else alarm(15 * 60, OwnWifi.class); } if (SipdroidEngine.pwl != null) for (PowerManager.WakeLock pwl : SipdroidEngine.pwl) if (pwl != null && pwl.isHeld()) { pwl.release(); pwl.acquire(); } } else if (intentAction.equals(WifiManager.WIFI_STATE_CHANGED_ACTION)) { if (PreferenceManager.getDefaultSharedPreferences(mContext).getBoolean( org.sipdroid.sipua.ui.Settings.PREF_SELECTWIFI, org.sipdroid.sipua.ui.Settings.DEFAULT_SELECTWIFI)) mHandler.sendEmptyMessageDelayed(MSG_SCAN, 3000); } else if (intentAction.equals(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION)) { if (SystemClock.uptimeMillis() > lastscan + 45000 && PreferenceManager.getDefaultSharedPreferences(mContext).getBoolean( org.sipdroid.sipua.ui.Settings.PREF_SELECTWIFI, org.sipdroid.sipua.ui.Settings.DEFAULT_SELECTWIFI)) { WifiManager wm = (WifiManager) mContext.getSystemService(Context.WIFI_SERVICE); WifiInfo wi = wm.getConnectionInfo(); String activeSSID = null; if (wi != null) activeSSID = wi.getSSID(); if (activeSSID != null && (activeSSID.length() == 0 || activeSSID.equals("0x"))) activeSSID = null; List<ScanResult> mScanResults = wm.getScanResults(); List<WifiConfiguration> configurations = wm.getConfiguredNetworks(); if (configurations != null) { WifiConfiguration bestconfig = null, maxconfig = null, activeconfig = null; for (final WifiConfiguration config : configurations) { if (maxconfig == null || config.priority > maxconfig.priority) { maxconfig = config; } if (config.SSID != null && (config.SSID.equals("\"" + activeSSID + "\"") || config.SSID.equals(activeSSID))) activeconfig = config; } ScanResult bestscan = null, activescan = null; if (mScanResults != null) for (final ScanResult scan : mScanResults) { for (final WifiConfiguration config : configurations) { if (config.SSID != null && config.SSID.equals("\"" + scan.SSID + "\"")) { if (bestscan == null || scan.level > bestscan.level) { bestscan = scan; bestconfig = config; } if (config == activeconfig) activescan = scan; } } } if (activescan != null) System.out.println("debug wifi asu(active)" + asu(activescan)); if (bestconfig != null && (activeconfig == null || bestconfig.priority != activeconfig.priority) && asu(bestscan) > asu(activescan) * 1.5 && /* (activeSSID == null || activescan != null) && */ asu(bestscan) > 22) { if (!Sipdroid.release) Log.i("SipUA:", "changing to " + bestconfig.SSID); if (activeSSID == null || !activeSSID.equals(bestscan.SSID)) wm.disconnect(); bestconfig.priority = maxconfig.priority + 1; wm.updateNetwork(bestconfig); wm.enableNetwork(bestconfig.networkId, true); wm.saveConfiguration(); if (activeSSID == null || !activeSSID.equals(bestscan.SSID)) wm.reconnect(); lastscan = SystemClock.uptimeMillis(); } else if (activescan != null && asu(activescan) < 15) { wm.disconnect(); wm.disableNetwork(activeconfig.networkId); wm.saveConfiguration(); } } } } }
From source file:com.grazerss.EntryManager.java
boolean isOnWiFi() { if (connectivityManager == null) { connectivityManager = (ConnectivityManager) ctx.getSystemService(Context.CONNECTIVITY_SERVICE); }/* ww w. ja v a 2 s. c o m*/ if (connectivityManager == null) { PL.log("EntryManager. Wasn't able to get CONNECTIVITY_SERVICE.", ctx); WifiManager wifiManager = (WifiManager) ctx.getSystemService(Context.WIFI_SERVICE); WifiInfo wifiInfo = wifiManager.getConnectionInfo(); if (wifiInfo != null) { PL.log("WiFi Info=" + wifiInfo + " SSID=" + wifiInfo.getSSID(), ctx); } return false; } final NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo(); if (networkInfo == null) { PL.log("EntryManager. Wasn't able to get Network Info.", ctx); return false; } if (ConnectivityManager.TYPE_WIFI != networkInfo.getType()) { PL.log("EntryManager. Network Info Type was not WiFi, but " + networkInfo.getType() + ".", ctx); return false; } return true; }