Example usage for android.net.wifi WifiInfo getNetworkId

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

Introduction

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

Prototype

public int getNetworkId() 

Source Link

Document

Each configured network has a unique small integer ID, used to identify the network when performing operations on the supplicant.

Usage

From source file:com.wifi.brainbreaker.mydemo.spydroid.ui.HandsetFragment.java

private void displayIpAddress() {
    WifiManager wifiManager = (WifiManager) mApplication.getApplicationContext()
            .getSystemService(Context.WIFI_SERVICE);
    WifiInfo info = wifiManager.getConnectionInfo();
    String ipaddress = null;/*from  w ww  .j ava  2  s.c  o  m*/
    if (info != null && info.getNetworkId() > -1) {
        int i = info.getIpAddress();
        String ip = String.format(Locale.ENGLISH, "%d.%d.%d.%d", i & 0xff, i >> 8 & 0xff, i >> 16 & 0xff,
                i >> 24 & 0xff);
        mLine1.setText(mHttpServer.isHttpsEnabled() ? "https://" : "http://");
        mLine1.append(ip);
        mLine1.append(":" + mHttpServer.getHttpPort());
        mLine2.setText("rtsp://");
        mLine2.append(ip);
        mLine2.append(":" + mRtspServer.getPort());
        streamingState(0);
    } else if ((ipaddress = Utilities.getLocalIpAddress(true)) != null) {
        mLine1.setText(mHttpServer.isHttpsEnabled() ? "https://" : "http://");
        mLine1.append(ipaddress);
        mLine1.append(":" + mHttpServer.getHttpPort());
        mLine2.setText("rtsp://");
        mLine2.append(ipaddress);
        mLine2.append(":" + mRtspServer.getPort());
        streamingState(0);
    } else {
        streamingState(2);
    }

}

From source file:net.majorkernelpanic.spydroid.ui.HandsetFragment.java

public void displayIpAddress() {
    WifiManager wifiManager = (WifiManager) SpydroidApplication.getContext()
            .getSystemService(Context.WIFI_SERVICE);
    WifiInfo info = wifiManager.getConnectionInfo();
    String ipaddress = null;/*from  w  w w.j a v a 2s.  c  o  m*/
    Log.d("SpydroidActivity", "getNetworkId " + info.getNetworkId());
    if (info != null && info.getNetworkId() > -1) {
        int i = info.getIpAddress();
        String ip = String.format(Locale.ENGLISH, "%d.%d.%d.%d", i & 0xff, i >> 8 & 0xff, i >> 16 & 0xff,
                i >> 24 & 0xff);
        mLine1.setText("http://");
        mLine1.append(ip);
        mLine1.append(":" + SpydroidApplication.sHttpPort);
        mLine2.setText("rtsp://");
        mLine2.append(ip);
        mLine2.append(":" + SpydroidApplication.sRtspPort);
        streamingState(0);
    } else if ((ipaddress = Utilities.getLocalIpAddress(true)) != null) {
        mLine1.setText("http://");
        mLine1.append(ipaddress);
        mLine1.append(":" + SpydroidApplication.sHttpPort);
        mLine2.setText("rtsp://");
        mLine2.append(ipaddress);
        mLine2.append(":" + SpydroidApplication.sRtspPort);
        streamingState(0);
    } else {
        mLine1.setText("HTTP://xxx.xxx.xxx.xxx:" + SpydroidApplication.sHttpPort);
        mLine2.setText("RTSP://xxx.xxx.xxx.xxx:" + SpydroidApplication.sHttpPort);
        streamingState(2);
    }
}

From source file:org.noise_planet.noisecapture.MainActivity.java

private boolean checkWifiState() {

    // Check connection state
    WifiManager wifiMgr = (WifiManager) getSystemService(Context.WIFI_SERVICE);
    if (wifiMgr.isWifiEnabled()) { // WiFi adapter is ON
        WifiInfo wifiInfo = wifiMgr.getConnectionInfo();
        if (wifiInfo.getNetworkId() == -1) {
            return false; // Not connected to an access-Point
        }//from ww  w .  ja  va  2s  .  c  om
        // Connected to an Access Point
        return true;
    } else {
        return false; // WiFi adapter is OFF
    }
}

From source file:org.universAAL.android.services.MiddlewareService.java

/**
 * Check what is the current connection status of WiFi.
 * /*  ww w.  j  av  a 2 s.  c om*/
 * @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:com.wheelphone.remotemini.WheelphoneRemoteMini.java

private void displayIpAddress() {
    WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
    WifiInfo info = wifiManager.getConnectionInfo();
    if (info != null && info.getNetworkId() > -1) {
        int i = info.getIpAddress();
        String ip = String.format("%d.%d.%d.%d", i & 0xff, i >> 8 & 0xff, i >> 16 & 0xff, i >> 24 & 0xff);
        line1.setText("HTTP://");
        line1.append(ip);//from w w w  .  jav  a 2s.c  o m
        line1.append(":8080");
        line2.setText("RTSP://");
        line2.append(ip);
        line2.append(":8086");
        streamingState(0);
    } else {
        line1.setText("HTTP://xxx.xxx.xxx.xxx:8080");
        line2.setText("RTSP://xxx.xxx.xxx.xxx:8086");
        streamingState(2);
    }
}

From source file:at.alladin.rmbt.android.util.InformationCollector.java

private void getWiFiInfo() {
    initNetwork();//w  ww  . j  av a2s . co  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());
            }
        }
    }
}