Example usage for android.net.wifi WifiInfo getSSID

List of usage examples for android.net.wifi WifiInfo getSSID

Introduction

In this page you can find the example usage for android.net.wifi WifiInfo getSSID.

Prototype

public String getSSID() 

Source Link

Document

Returns the service set identifier (SSID) of the current 802.11 network.

Usage

From source file:Main.java

public static String getCurrentWifiLink(Context context) {
    if (context == null)
        return null;

    final WifiManager wifiMgr = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);

    final WifiInfo connectedWifi = wifiMgr.getConnectionInfo();
    final String connectedSSID = connectedWifi == null ? null : connectedWifi.getSSID().replace("\"", "");
    return connectedSSID;
}

From source file:Main.java

/**
 * Returns SSID of Wifi hotspot device connected with.
 * @param context/*ww w.  ja v  a 2 s  .c  o  m*/
 * @return
 */
public static String getCurrentWifiConnectionSSID(Context context) {
    final WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
    final WifiInfo wifiInfo = wifiManager.getConnectionInfo();
    if (wifiInfo == null)
        return null;

    String ssid = wifiInfo.getSSID();
    if (android.os.Build.VERSION.SDK_INT >= 16) {
        if (ssid.startsWith("\"") && ssid.endsWith("\"")) {
            ssid = ssid.substring(1, ssid.length() - 1);
        }
    }
    return ssid;
}

From source file:alaindc.crowdroid.RadioUtils.java

public static String[] getWifiInfo(Context context) {
    try {// ww w . j a  va 2s. com
        WifiManager wifiMan = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
        WifiInfo wifiInfo = wifiMan.getConnectionInfo();

        String bssid = wifiInfo.getBSSID();
        String ssid = wifiInfo.getSSID();
        String signalStrength = String.valueOf(wifiInfo.getRssi());

        // Update view
        Intent senseintent = new Intent(Constants.INTENT_UPDATE_SENSORS);
        senseintent.putExtra(Constants.INTENT_RECEIVED_DATA_EXTRA_DATA, ssid + " " + signalStrength);
        LocalBroadcastManager.getInstance(context).sendBroadcast(senseintent);

        return new String[] { bssid, ssid, signalStrength };
    } catch (Exception e) {
        return new String[] { "", "", "" };
    }

}

From source file:com.google.android.libraries.cast.companionlibrary.utils.Utils.java

/**
 * Returns the SSID of the wifi connection, or <code>null</code> if there is no wifi.
 *//* ww  w  .j a  va  2  s  .co m*/
public static String getWifiSsid(Context context) {
    WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
    WifiInfo wifiInfo = wifiManager.getConnectionInfo();
    if (wifiInfo != null) {
        return wifiInfo.getSSID();
    }
    return null;
}

From source file:com.google.sample.castcompanionlibrary.utils.Utils.java

/**
 * Returns the SSID of the wifi connection, or <code>null</code> if there is no wifi.
 *
 * @param context/*w w  w.  ja v a  2 s .  co m*/
 * @return
 */
public static String getWifiSsid(Context context) {
    WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
    WifiInfo wifiInfo = wifiManager.getConnectionInfo();
    if (null != wifiInfo) {
        return wifiInfo.getSSID();
    }
    return null;
}

From source file:com.eurotong.orderhelperandroid.Common.java

public static String GetWifiSSID() {
    String id = "UNKNOWN";
    WifiManager wifiMan = (WifiManager) MyApplication.getAppContext().getSystemService(Context.WIFI_SERVICE);
    WifiInfo wifiInfo = wifiMan.getConnectionInfo();
    id = wifiInfo.getSSID().toString();
    return id;// www.j ava  2s.c om
}

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 ww  .  jav  a 2  s.c o m
        }
    }
    return ssid;
}

From source file:com.googlecode.android_scripting.jsonrpc.JsonBuilder.java

private static JSONObject buildJsonWifiInfo(WifiInfo data) throws JSONException {
    JSONObject result = new JSONObject();
    result.put("hidden_ssid", data.getHiddenSSID());
    result.put("ip_address", data.getIpAddress());
    result.put("link_speed", data.getLinkSpeed());
    result.put("network_id", data.getNetworkId());
    result.put("rssi", data.getRssi());
    result.put("bssid", data.getBSSID());
    result.put("mac_address", data.getMacAddress());
    result.put("ssid", data.getSSID());
    String supplicantState = "";
    switch (data.getSupplicantState()) {
    case ASSOCIATED:
        supplicantState = "associated";
        break;/*from   www .  j  av  a  2  s  .c o  m*/
    case ASSOCIATING:
        supplicantState = "associating";
        break;
    case COMPLETED:
        supplicantState = "completed";
        break;
    case DISCONNECTED:
        supplicantState = "disconnected";
        break;
    case DORMANT:
        supplicantState = "dormant";
        break;
    case FOUR_WAY_HANDSHAKE:
        supplicantState = "four_way_handshake";
        break;
    case GROUP_HANDSHAKE:
        supplicantState = "group_handshake";
        break;
    case INACTIVE:
        supplicantState = "inactive";
        break;
    case INVALID:
        supplicantState = "invalid";
        break;
    case SCANNING:
        supplicantState = "scanning";
        break;
    case UNINITIALIZED:
        supplicantState = "uninitialized";
        break;
    default:
        supplicantState = null;
    }
    result.put("supplicant_state", build(supplicantState));
    return result;
}

From source file:com.swisscom.safeconnect.fragment.InfoFragment.java

private String getConnectedSSID() {
    String ssid = null;//from   w w w . ja  v a 2  s  . c  o  m
    ConnectivityManager connManager = (ConnectivityManager) getActivity()
            .getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo networkInfo = connManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
    if (networkInfo.isConnected()) {
        final WifiManager wifiManager = (WifiManager) getActivity().getSystemService(Context.WIFI_SERVICE);
        final WifiInfo connectionInfo = wifiManager.getConnectionInfo();
        if (connectionInfo != null && !TextUtils.isEmpty(connectionInfo.getSSID())) {
            ssid = connectionInfo.getSSID();
        }
    }
    return ssid;
}

From source file:com.bangz.smartmute.WifiEditActivity.java

@Override
public void onSuccessUpdateDatabase(Uri uri) {

    if (bActivited == false)
        return;/*from  ww w.  j  a va  2 s. c o m*/

    ConnectivityManager cm = (ConnectivityManager) getSystemService(CONNECTIVITY_SERVICE);
    NetworkInfo ninfo = cm.getActiveNetworkInfo();

    if (ninfo != null && ninfo.isConnected() && ninfo.getType() == ConnectivityManager.TYPE_WIFI) {
        WifiManager wifiManager = (WifiManager) getSystemService(WIFI_SERVICE);
        if (wifiManager != null) {
            WifiInfo wifiInfo = wifiManager.getConnectionInfo();
            String currssid = wifiInfo.getSSID();
            if (currssid.equals(strSSID)) {
                WifiMuteService.wifiConnected(this, strSSID);
            }
        }
    }

}