Example usage for android.net.wifi WifiInfo getBSSID

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

Introduction

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

Prototype

public String getBSSID() 

Source Link

Document

Return the basic service set identifier (BSSID) of the current access point.

Usage

From source file:alaindc.crowdroid.RadioUtils.java

public static String[] getWifiInfo(Context context) {
    try {//from w w w . ja v a  2s  . c o  m
        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.vinexs.tool.NetworkManager.java

public static String getSSID(Context context) {
    WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
    WifiInfo info = wifiManager.getConnectionInfo();
    return info.getBSSID();
}

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   w  w  w  .j ava 2s .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.github.pwittchen.reactivewifi.app.MainActivity.java

private void startWifiInfoSubscription() {
    wifiInfoSubscription = ReactiveWifi.observeWifiAccessPointChanges(getApplicationContext())
            .subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread())
            .subscribe(new Action1<WifiInfo>() {
                @Override/*  w  ww  .j  a va 2s  .  c o m*/
                public void call(WifiInfo wifiInfo) {
                    Log.d("ReactiveWifi", "New BSSID: " + wifiInfo.getBSSID());
                }
            });
}

From source file:com.vrem.wifianalyzer.wifi.scanner.Transformer.java

protected WiFiConnection transformWifiInfo(WifiInfo wifiInfo) {
    if (wifiInfo == null || wifiInfo.getNetworkId() == -1) {
        return WiFiConnection.EMPTY;
    }//from   ww  w  .j  a v  a  2s  . co m
    return new WiFiConnection(WiFiUtils.convertSSID(wifiInfo.getSSID()), wifiInfo.getBSSID(),
            WiFiUtils.convertIpAddress(wifiInfo.getIpAddress()), wifiInfo.getLinkSpeed());
}

From source file:ch.ethz.coss.nervousnet.vm.sensors.ConnectivitySensor.java

public void runConnectivitySensor() {
    Log.d(LOG_TAG, "Inside runConnectivitySensor");
    if (Build.VERSION.SDK_INT >= 23 && ContextCompat.checkSelfPermission(context,
            android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
        return;/*from  w  w  w . j a  v  a2 s .  c o  m*/
    }
    ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo activeNetwork = cm.getActiveNetworkInfo();
    boolean isConnected = activeNetwork != null && activeNetwork.isConnectedOrConnecting();
    int networkType = -1;
    boolean isRoaming = false;
    if (isConnected) {
        networkType = activeNetwork.getType();
        isRoaming = activeNetwork.isRoaming();
    }

    String wifiHashId = "";
    int wifiStrength = Integer.MIN_VALUE;

    if (networkType == ConnectivityManager.TYPE_WIFI) {
        WifiManager wm = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
        WifiInfo wi = wm.getConnectionInfo();
        StringBuilder wifiInfoBuilder = new StringBuilder();
        wifiInfoBuilder.append(wi.getBSSID());
        wifiInfoBuilder.append(wi.getSSID());
        try {
            MessageDigest messageDigest = MessageDigest.getInstance("SHA-256");
            messageDigest.update(wifiInfoBuilder.toString().getBytes());
            wifiHashId = new String(messageDigest.digest());
        } catch (NoSuchAlgorithmException e) {
        }
        wifiStrength = wi.getRssi();
    }

    byte[] cdmaHashId = new byte[32];
    byte[] lteHashId = new byte[32];
    byte[] gsmHashId = new byte[32];
    byte[] wcdmaHashId = new byte[32];

    TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);

    List<CellInfo> cis = tm.getAllCellInfo();
    if (cis != null) {
        // New method
        for (CellInfo ci : cis) {
            if (ci.isRegistered()) {
                if (ci instanceof CellInfoCdma) {
                    CellInfoCdma cic = (CellInfoCdma) ci;
                    cdmaHashId = generateMobileDigestId(cic.getCellIdentity().getSystemId(),
                            cic.getCellIdentity().getNetworkId(), cic.getCellIdentity().getBasestationId());
                }
                if (ci instanceof CellInfoGsm) {
                    CellInfoGsm cic = (CellInfoGsm) ci;
                    gsmHashId = generateMobileDigestId(cic.getCellIdentity().getMcc(),
                            cic.getCellIdentity().getMnc(), cic.getCellIdentity().getCid());
                }
                if (ci instanceof CellInfoLte) {
                    CellInfoLte cic = (CellInfoLte) ci;
                    lteHashId = generateMobileDigestId(cic.getCellIdentity().getMcc(),
                            cic.getCellIdentity().getMnc(), cic.getCellIdentity().getCi());
                }
                if (ci instanceof CellInfoWcdma) {
                    CellInfoWcdma cic = (CellInfoWcdma) ci;
                    wcdmaHashId = generateMobileDigestId(cic.getCellIdentity().getMcc(),
                            cic.getCellIdentity().getMnc(), cic.getCellIdentity().getCid());
                }
            }
        }
    } else {
        // Legacy method
        CellLocation cl = tm.getCellLocation();
        if (cl instanceof CdmaCellLocation) {
            CdmaCellLocation cic = (CdmaCellLocation) cl;
            cdmaHashId = generateMobileDigestId(cic.getSystemId(), cic.getNetworkId(), cic.getBaseStationId());
        }
        if (cl instanceof GsmCellLocation) {
            GsmCellLocation cic = (GsmCellLocation) cl;
            gsmHashId = generateMobileDigestId(cic.getLac(), 0, cic.getCid());
        }
    }

    StringBuilder mobileHashBuilder = new StringBuilder();
    mobileHashBuilder.append(new String(cdmaHashId));
    mobileHashBuilder.append(new String(lteHashId));
    mobileHashBuilder.append(new String(gsmHashId));
    mobileHashBuilder.append(new String(wcdmaHashId));

    dataReady(new ConnectivityReading(System.currentTimeMillis(), isConnected, networkType, isRoaming,
            wifiHashId, wifiStrength, mobileHashBuilder.toString()));

}

From source file:org.pidome.client.phone.services.SystemService.java

private void setHome() {
    if (prefs != null) {
        if (prefs.getBoolPreference("wifiConnectHomeEnabled", false)) {
            ConnectivityManager connManager = (ConnectivityManager) getSystemService(
                    Context.CONNECTIVITY_SERVICE);
            NetworkInfo networkInfo = connManager.getActiveNetworkInfo();
            if (networkInfo.isConnected() && networkInfo.getType() == ConnectivityManager.TYPE_WIFI) {
                final WifiManager wifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE);
                final WifiInfo connectionInfo = wifiManager.getConnectionInfo();
                if (connectionInfo != null) {
                    String SSID = connectionInfo.getSSID();
                    String BSSID = connectionInfo.getBSSID();
                    if (SSID != null && BSSID != null) {
                        if (SSID.equals(prefs.getStringPreference("wifiConnectSSID",
                                java.util.UUID.randomUUID().toString()))
                                && BSSID.equals(prefs.getStringPreference("wifiConnectBSSID",
                                        java.util.UUID.randomUUID().toString()))) {
                            if (this.system != null) {
                                try {
                                    system.getClient().getEntities().getPresenceService().setPresence(1);
                                } catch (EntityNotAvailableException ex) {
                                    Logger.getLogger(SystemService.class.getName()).log(Level.SEVERE, null, ex);
                                }//w  w  w .  ja  v a 2  s .c o  m
                            }
                        }
                    }
                }
            }
        }
    }
}

From source file:com.jtechme.apphub.views.ManageReposActivity.java

private void checkIfNewRepoOnSameWifi(NewRepoConfig newRepo) {
    // if this is a local repo, check we're on the same wifi
    if (!TextUtils.isEmpty(newRepo.getBssid())) {
        WifiManager wifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE);
        WifiInfo wifiInfo = wifiManager.getConnectionInfo();
        String bssid = wifiInfo.getBSSID();
        if (TextUtils.isEmpty(bssid)) /* not all devices have wifi */
            return;
        bssid = bssid.toLowerCase(Locale.ENGLISH);
        String newRepoBssid = Uri.decode(newRepo.getBssid()).toLowerCase(Locale.ENGLISH);
        if (!bssid.equals(newRepoBssid)) {
            String msg = String.format(getString(R.string.not_on_same_wifi), newRepo.getSsid());
            Toast.makeText(this, msg, Toast.LENGTH_LONG).show();
        }/*from  w w  w . j ava  2s .  co m*/
        // TODO we should help the user to the right thing here,
        // instead of just showing a message!
    }
}

From source file:mobisocial.musubi.ui.NearbyActivity.java

private void doCheckin() {
    WifiInfo wifi = mWifiManager.getConnectionInfo();
    String myWifiName = wifi.getSSID();
    if (myWifiName == null) {
        /**/*from   w w w  .ja  v  a  2  s  .c om*/
         * TODO:
         * Depending on desired outcome, either help them get on wifi
         * or try connecting to gps server, etc.
         */
        toast("No wifi network available.");
        return;
    }

    String myWifiId = wifi.getBSSID();
    String myIp = formatIp(wifi.getIpAddress());
    String myWifiFingerprint = Util.computeWifiFingerprint(mWifiManager.getScanResults());

    if (DBG)
        Log.d(TAG, "Checking in to " + myWifiName + "...");
    JSONObject loc = new JSONObject();
    try {
        loc.put(DbContactAttributes.ATTR_WIFI_SSID, myWifiName);
        if (myWifiId != null) {
            loc.put(DbContactAttributes.ATTR_WIFI_BSSID, myWifiId);
        }
        if (myIp != null) {
            loc.put(DbContactAttributes.ATTR_LAN_IP, myIp);
        }
        loc.put(DbContactAttributes.ATTR_WIFI_FINGERPRINT, myWifiFingerprint);
    } catch (JSONException e) {
        // Impossible json exception
    }

    //XXX killed for now
    //mMusubi.getAppFeed().postObj(new MemObj("locUpdate", loc));
    //toast("Checked in to '" + myWifiName + "'.");
}