Java Code Examples for android.net.wifi.WifiInfo#getSSID()
The following examples show how to use
android.net.wifi.WifiInfo#getSSID() .
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: JoH.java From xDrip-plus with GNU General Public License v3.0 | 6 votes |
public static String getWifiSSID() { try { final WifiManager wifi_manager = (WifiManager) xdrip.getAppContext().getApplicationContext().getSystemService(Context.WIFI_SERVICE); if (wifi_manager.isWifiEnabled()) { final WifiInfo wifiInfo = wifi_manager.getConnectionInfo(); if (wifiInfo != null) { final NetworkInfo.DetailedState wifi_state = WifiInfo.getDetailedStateOf(wifiInfo.getSupplicantState()); if (wifi_state == NetworkInfo.DetailedState.CONNECTED || wifi_state == NetworkInfo.DetailedState.OBTAINING_IPADDR || wifi_state == NetworkInfo.DetailedState.CAPTIVE_PORTAL_CHECK) { String ssid = wifiInfo.getSSID(); if (ssid.equals("<unknown ssid>")) return null; // WifiSsid.NONE; if (ssid.charAt(0) == '"') ssid = ssid.substring(1); if (ssid.charAt(ssid.length() - 1) == '"') ssid = ssid.substring(0, ssid.length() - 1); return ssid; } } } } catch (Exception e) { Log.e(TAG, "Got exception in getWifiSSID: " + e); } return null; }
Example 2
Source File: Utils.java From RPiCameraViewer with MIT License | 6 votes |
public static String getNetworkName() { String ssid = ""; WifiManager manager = (WifiManager)App.getContext().getApplicationContext().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("^\"|\"$", ""); if (ssid.equals("<unknown ssid>")) { ssid = App.getStr(R.string.unknown_network); } } } } return ssid; }
Example 3
Source File: PlatformNetworksManager.java From 365browser with Apache License 2.0 | 6 votes |
static VisibleWifi getConnectedWifi(Context context, WifiManager wifiManager) { if (!hasLocationAndWifiPermission(context)) { return VisibleWifi.NO_WIFI_INFO; } WifiInfo wifiInfo = wifiManager.getConnectionInfo(); if (wifiInfo == null) { return VisibleWifi.NO_WIFI_INFO; } String ssid = wifiInfo.getSSID(); if (ssid == null || UNKNOWN_SSID.equals(ssid)) { // No SSID. ssid = null; } else { // Remove double quotation if ssid has double quotation. if (ssid.startsWith("\"") && ssid.endsWith("\"") && ssid.length() > 2) { ssid = ssid.substring(1, ssid.length() - 1); } } String bssid = wifiInfo.getBSSID(); // It's connected, so use current time. return VisibleWifi.create(ssid, bssid, null, sTimeProvider.getCurrentTime()); }
Example 4
Source File: JoH.java From xDrip with GNU General Public License v3.0 | 6 votes |
public static String getWifiSSID() { try { final WifiManager wifi_manager = (WifiManager) xdrip.getAppContext().getApplicationContext().getSystemService(Context.WIFI_SERVICE); if (wifi_manager.isWifiEnabled()) { final WifiInfo wifiInfo = wifi_manager.getConnectionInfo(); if (wifiInfo != null) { final NetworkInfo.DetailedState wifi_state = WifiInfo.getDetailedStateOf(wifiInfo.getSupplicantState()); if (wifi_state == NetworkInfo.DetailedState.CONNECTED || wifi_state == NetworkInfo.DetailedState.OBTAINING_IPADDR || wifi_state == NetworkInfo.DetailedState.CAPTIVE_PORTAL_CHECK) { String ssid = wifiInfo.getSSID(); if (ssid.equals("<unknown ssid>")) return null; // WifiSsid.NONE; if (ssid.charAt(0) == '"') ssid = ssid.substring(1); if (ssid.charAt(ssid.length() - 1) == '"') ssid = ssid.substring(0, ssid.length() - 1); return ssid; } } } } catch (Exception e) { Log.e(TAG, "Got exception in getWifiSSID: " + e); } return null; }
Example 5
Source File: NetUtils.java From gokit-android with MIT License | 6 votes |
/** * 获取当前WIFI的SSID. * * @param context * 上下文 * @return ssid * * * */ public static String getCurentWifiSSID(Context context) { String ssid = ""; if (context != null) { WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); WifiInfo wifiInfo = wifiManager.getConnectionInfo(); if(wifiInfo!=null){ ssid = wifiInfo.getSSID(); if (ssid.substring(0, 1).equals("\"") && ssid.substring(ssid.length() - 1).equals("\"")) { ssid = ssid.substring(1, ssid.length() - 1); } } } return ssid; }
Example 6
Source File: XLUtil.java From BtPlayer with Apache License 2.0 | 5 votes |
public static String getSSID(Context context) { if (context == null) { XLLog.e(TAG, "getSSID, context invalid"); return null; } WifiManager wifiManager = (WifiManager) context.getSystemService("wifi"); if (wifiManager != null) { WifiInfo connectionInfo = wifiManager.getConnectionInfo(); if (connectionInfo != null) { return connectionInfo.getSSID(); } } return null; }
Example 7
Source File: Wifi.java From Multiwii-Remote with Apache License 2.0 | 5 votes |
public String getCurrentSSID() { String ssid = null; ConnectivityManager connManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo networkInfo = connManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI); if (networkInfo.isConnected()) { final WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); final WifiInfo connectionInfo = wifiManager.getConnectionInfo(); if (connectionInfo != null && !TextUtils.isEmpty(connectionInfo.getSSID())) { ssid = connectionInfo.getSSID(); } } return ssid; }
Example 8
Source File: JacksonActivity.java From My-MVP with Apache License 2.0 | 5 votes |
@Nullable private String getWifiSSID() { WifiManager wifiManager = (WifiManager) getApplicationContext().getSystemService(Context.WIFI_SERVICE); if (wifiManager != null && wifiManager.isWifiEnabled()) { WifiInfo wifiInfo = wifiManager.getConnectionInfo(); if (wifiInfo != null) { NetworkInfo.DetailedState state = WifiInfo.getDetailedStateOf(wifiInfo.getSupplicantState()); if (state == NetworkInfo.DetailedState.CONNECTED || state == NetworkInfo.DetailedState.OBTAINING_IPADDR) { return wifiInfo.getSSID(); } } } // Optional.ofNullable(wifiManager).ifPresent((WifiManager wifiManager1) -> { // if (wifiManager1.isWifiEnabled()) { // WifiInfo wifiInfo = wifiManager1.getConnectionInfo(); // Optional.ofNullable(wifiInfo).ifPresent((Consumer<WifiInfo>) (WifiInfo wifiInfo1) -> { // NetworkInfo.DetailedState detailedState = WifiInfo.getDetailedStateOf(wifiInfo1.getSupplicantState()); // if (detailedState == NetworkInfo.DetailedState.CONNECTED || detailedState == NetworkInfo.DetailedState.OBTAINING_IPADDR) { // // return wifiInfo1.getSSID(); // } // }); // } // // // }); return null; }
Example 9
Source File: NetworkConnUtil.java From RairDemo with Apache License 2.0 | 5 votes |
/** * 获取Wifi的Ssid * * @param context * @return */ public static String getWifiSsid(Context context) { String ssid = ""; try { final NetworkInfo network = ((ConnectivityManager) context .getSystemService(Context.CONNECTIVITY_SERVICE)) .getActiveNetworkInfo(); if (network != null && network.isAvailable() && network.isConnected()) { int type = network.getType(); if (type == ConnectivityManager.TYPE_WIFI) { WifiManager wifiManager = (WifiManager) context .getSystemService(Context.WIFI_SERVICE); WifiInfo wifiInfo = wifiManager.getConnectionInfo(); if (wifiInfo != null) { ssid = wifiInfo.getSSID(); if (ssid == null) { ssid = ""; } ssid = ssid.replaceAll("\"", ""); } } } } catch (Exception e) { e.printStackTrace(); } return ssid; }
Example 10
Source File: WifiTools.java From WiFiAfterConnect with Apache License 2.0 | 5 votes |
public static String getSSID(Context context) { if (context != null) { WifiManager wifiMan = (WifiManager)context.getSystemService(Context.WIFI_SERVICE); if (wifiMan != null) { WifiInfo info = wifiMan.getConnectionInfo(); if (info != null) { return info.getSSID(); } } } return null; }
Example 11
Source File: WifiSetupActivity.java From STGUploader with MIT License | 5 votes |
private void updateWifiSwitch() { boolean wifiEnabled = isWifiEnabled(); String summary; if (wifiEnabled) { NetworkInfo networkInfo = connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI); WifiInfo wifiInfo = wifiManager.getConnectionInfo(); if (networkInfo.isConnected()) { summary = res.getString(R.string.connectionStateConnectedTo) + " " + wifiInfo.getSSID(); startLoginActivity(); } else { NetworkInfo.DetailedState state = WifiInfo.getDetailedStateOf(wifiInfo.getSupplicantState()); switch (state) { case SCANNING: summary = res.getString(R.string.connectionStateWifiScanning); break; case AUTHENTICATING: case CONNECTING: case OBTAINING_IPADDR: summary = res.getString(R.string.connectionStateConnecting); break; default: summary = res.getString(R.string.connectionStateWifiEnabled); } } } else { summary = res.getString(R.string.connectionStateWifiDisabled); } textViewWifiState.setText(summary); }
Example 12
Source File: NetworkMonitorAutoDetect.java From webrtc_android with MIT License | 5 votes |
String getWifiSSID() { final Intent intent = context.registerReceiver( null, new IntentFilter(WifiManager.NETWORK_STATE_CHANGED_ACTION)); if (intent != null) { final WifiInfo wifiInfo = intent.getParcelableExtra(WifiManager.EXTRA_WIFI_INFO); if (wifiInfo != null) { final String ssid = wifiInfo.getSSID(); if (ssid != null) { return ssid; } } } return ""; }
Example 13
Source File: ApConnector.java From spark-setup-android with Apache License 2.0 | 5 votes |
private void onWifiChangeBroadcastReceived(Intent intent, WifiConfiguration config) { // this will only be present if the new state is CONNECTED WifiInfo wifiInfo = intent.getParcelableExtra(WifiManager.EXTRA_WIFI_INFO); if (wifiInfo == null || wifiInfo.getSSID() == null) { // no WifiInfo or SSID means we're not interested. return; } SSID newlyConnectedSSID = SSID.from(wifiInfo); log.i("Connected to: " + newlyConnectedSSID); if (newlyConnectedSSID.equals(SSID.from(config))) { // FIXME: find a way to record success in memory in case this happens to happen // during a config change (etc)? client.onApConnectionSuccessful(config); } }
Example 14
Source File: WifiApListProvider.java From PrivacyStreams with Apache License 2.0 | 5 votes |
@Override public void onReceive(Context context, Intent intent) { WifiManager wifiMgr = (WifiManager) context.getApplicationContext().getSystemService(Context.WIFI_SERVICE); WifiInfo wifiInfo = wifiMgr.getConnectionInfo(); String name = wifiInfo.getSSID(); for(ScanResult result: wifiMgr.getScanResults()){ WifiApListProvider.this.output(new WifiAp(result, name.equals(result.SSID))); } WifiApListProvider.this.finish(); }
Example 15
Source File: NetworkUtils.java From fangzhuishushenqi with Apache License 2.0 | 5 votes |
/** * 获取当前连接wifi的名称 * * @return */ public static String getConnectWifiSsid(Context context) { if (isWifiConnected(context)) { WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); WifiInfo wifiInfo = wifiManager.getConnectionInfo(); return wifiInfo.getSSID(); } return null; }
Example 16
Source File: NetUtils.java From gokit-android with MIT License | 5 votes |
static public String getConnectWifiSsid(Context c) { String ssid = ""; WifiManager wifiManager = (WifiManager) c.getSystemService(Context.WIFI_SERVICE); WifiInfo wifiInfo = wifiManager.getConnectionInfo(); if(wifiInfo!=null){ ssid = wifiInfo.getSSID(); } return ssid; }
Example 17
Source File: NetUtils.java From Gizwits-SmartBuld_Android with MIT License | 5 votes |
/** * 获取当前WIFI的SSID. * * @param context * 上下文 * @return ssid * * * */ public static String getCurentWifiSSID(Context context) { String ssid = ""; if (context != null) { WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); WifiInfo wifiInfo = wifiManager.getConnectionInfo(); ssid = wifiInfo.getSSID(); if (ssid.substring(0, 1).equals("\"") && ssid.substring(ssid.length() - 1).equals("\"")) { ssid = ssid.substring(1, ssid.length() - 1); } } return ssid; }
Example 18
Source File: NetworkUtils.java From BookReader with Apache License 2.0 | 5 votes |
/** * 获取当前连接wifi的名称 * * @return */ public static String getConnectWifiSsid(Context context) { if (isWifiConnected(context)) { WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); WifiInfo wifiInfo = wifiManager.getConnectionInfo(); return wifiInfo.getSSID(); } return null; }
Example 19
Source File: ConfigureDeviceFragment.java From RoMote with Apache License 2.0 | 4 votes |
private String getWirelessNetworkName(Context context) { String networkName = ""; final ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); if (cm == null) { return networkName; } final NetworkInfo activeNetwork = cm.getActiveNetworkInfo(); boolean isConnected = activeNetwork != null && activeNetwork.isConnectedOrConnecting(); boolean isWiFi = activeNetwork.getType() == ConnectivityManager.TYPE_WIFI; if (isConnected && isWiFi) { final WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); final WifiInfo connectionInfo = wifiManager.getConnectionInfo(); networkName = connectionInfo.getSSID(); } return networkName; }
Example 20
Source File: NetworkUtils.java From mirror with GNU General Public License v3.0 | 4 votes |
public static String getCurrentSSID(Context context) { WifiManager manager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); WifiInfo info = manager.getConnectionInfo(); return info != null && !TextUtils.isEmpty(info.getSSID()) ? info.getSSID() : context.getString(R.string.connect_status_default_ssid); }