Example usage for android.net.wifi WifiManager getConnectionInfo

List of usage examples for android.net.wifi WifiManager getConnectionInfo

Introduction

In this page you can find the example usage for android.net.wifi WifiManager getConnectionInfo.

Prototype

public WifiInfo getConnectionInfo() 

Source Link

Document

Return dynamic information about the current Wi-Fi connection, if any is active.

Usage

From source file:Main.java

public static String getDevicesMac(Context context) {
    WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
    if (!wifiManager.isWifiEnabled()) {
        wifiManager.setWifiEnabled(true);
    }//from  w  ww  .j  ava 2s  . c  om
    WifiInfo wifiInfo = wifiManager.getConnectionInfo();
    String mac = wifiInfo.getMacAddress().toString();
    return mac;
}

From source file:Main.java

public static String getLocalIpByWifi(Context context) {
    WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
    if (wifiManager == null) {
        return "wifiManager not found";
    }//w  ww. j  a v a 2s .  c om
    WifiInfo wifiInfo = wifiManager.getConnectionInfo();
    if (wifiInfo == null) {
        return "wifiInfo not found";
    }
    int ipAddress = wifiInfo.getIpAddress();
    return String.format("%d.%d.%d.%d", (ipAddress & 0xff), (ipAddress >> 8 & 0xff), (ipAddress >> 16 & 0xff),
            (ipAddress >> 24 & 0xff));
}

From source file:org.namelessrom.devicecontrol.net.NetworkInfo.java

public static String getWifiIp() {
    final WifiManager wifiManager = (WifiManager) Application.get().getSystemService(Context.WIFI_SERVICE);
    int ipAddress = wifiManager.getConnectionInfo().getIpAddress();
    if (ByteOrder.nativeOrder().equals(ByteOrder.LITTLE_ENDIAN)) {
        ipAddress = Integer.reverseBytes(ipAddress);
    }/*from w w  w  .  j a  v  a  2s  .com*/

    final byte[] ipByteArray = BigInteger.valueOf(ipAddress).toByteArray();

    String ipAddressString;
    try {
        ipAddressString = InetAddress.getByAddress(ipByteArray).getHostAddress();
    } catch (UnknownHostException ex) {
        ipAddressString = "0.0.0.0";
    }

    return ipAddressString;
}

From source file:Main.java

public static String getCurrentWifiIP(Application app) {
    WifiManager wifiManager = (WifiManager) app.getSystemService(Application.WIFI_SERVICE);
    if (!wifiManager.isWifiEnabled()) {
        return null;
    }//www . j a  v  a 2  s .co m

    WifiInfo wifiInfo = wifiManager.getConnectionInfo();

    int ipAddress = wifiInfo.getIpAddress();
    String strIPAddess = ((ipAddress >> 0) & 0xFF) + "." + ((ipAddress >> 8) & 0xFF) + "."
            + ((ipAddress >> 16) & 0xFF) + "." + ((ipAddress >> 24) & 0xFF);

    return strIPAddess;
}

From source file:alaindc.crowdroid.RadioUtils.java

public static String[] getWifiInfo(Context context) {
    try {/*  w w w .j  av  a2 s .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:Main.java

public static String getDevicesIP(Context context) {
    WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
    if (!wifiManager.isWifiEnabled()) {
        wifiManager.setWifiEnabled(true);
    }/*w  ww  .  j  av a2 s. c  o  m*/
    WifiInfo wifiInfo = wifiManager.getConnectionInfo();
    int ipAddress = wifiInfo.getIpAddress();
    String ip = (ipAddress & 0xFF) + "." + ((ipAddress >> 8) & 0xFF) + "." + ((ipAddress >> 16) & 0xFF) + "."
            + (ipAddress >> 24 & 0xFF);
    if (ip == null || ip.equals("0.0.0.0")) {

    }
    return ip;
}

From source file:Main.java

public static String getWIFIIP(Context context) {
    WifiManager wifimanage = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);

    if (!wifimanage.isWifiEnabled()) {
        wifimanage.setWifiEnabled(true);
    }//  w  w w  . j a v  a 2s.c om

    WifiInfo wifiinfo = wifimanage.getConnectionInfo();

    String ip = intToIp(wifiinfo.getIpAddress());
    return ip;
}

From source file:Main.java

public static String getWiFiIP(Context context) {
    WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
    if (!wifiManager.isWifiEnabled()) {
        wifiManager.setWifiEnabled(true);
    }/*from w  ww .  ja  v  a  2 s.  c om*/
    WifiInfo wifiinfo = wifiManager.getConnectionInfo();
    String ip = intToIp(wifiinfo.getIpAddress());

    return ip;
}

From source file:Main.java

public static final String getOblyDevicesID(Context mContext) {

    String m_szImei = "";
    try {/* www. j a v a 2s . c  o  m*/
        TelephonyManager TelephonyMgr = null;
        TelephonyMgr = (TelephonyManager) mContext.getSystemService(Activity.TELEPHONY_SERVICE);
        m_szImei = TelephonyMgr.getDeviceId();
    } catch (Exception ex) {
        ex.printStackTrace();
    }
    String m_szDevIDShort = null;
    try {
        m_szDevIDShort = "35" + //we make this look like a valid IMEI

                Build.BOARD.length() % 10 + Build.BRAND.length() % 10 + Build.CPU_ABI.length() % 10
                + Build.DEVICE.length() % 10 + Build.DISPLAY.length() % 10 + Build.HOST.length() % 10
                + Build.ID.length() % 10 + Build.MANUFACTURER.length() % 10 + Build.MODEL.length() % 10
                + Build.PRODUCT.length() % 10 + Build.TAGS.length() % 10 + Build.TYPE.length() % 10
                + Build.USER.length() % 10; //13 digits
    } catch (Exception ex) {
        ex.printStackTrace();
    }

    String m_szAndroidID = "";
    try {
        m_szAndroidID = "";
        Settings.Secure.getString(mContext.getContentResolver(), Settings.Secure.ANDROID_ID);
    } catch (Exception ex) {
        ex.printStackTrace();
    }
    String m_szWLANMAC = "";
    try {
        WifiManager wm = (WifiManager) mContext.getSystemService(Context.WIFI_SERVICE);
        m_szWLANMAC = wm.getConnectionInfo().getMacAddress();
    } catch (Exception ex) {
        ex.printStackTrace();
    }
    String m_szBTMAC = null;
    try {
        BluetoothAdapter m_BluetoothAdapter = null; // Local Bluetooth adapter
        m_BluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
        m_szBTMAC = m_BluetoothAdapter.getAddress();
    } catch (Exception ex) {
        ex.printStackTrace();
    }
    String m_szLongID = m_szImei + m_szDevIDShort + m_szAndroidID + m_szWLANMAC + m_szBTMAC;
    // compute md5
    MessageDigest m = null;
    try {
        m = MessageDigest.getInstance("MD5");
    } catch (NoSuchAlgorithmException e) {
        e.printStackTrace();
    }
    m.update(m_szLongID.getBytes(), 0, m_szLongID.length());
    // get md5 bytes
    byte p_md5Data[] = m.digest();
    // create a hex string
    String m_szUniqueID = new String();
    for (int i = 0; i < p_md5Data.length; i++) {
        int b = (0xFF & p_md5Data[i]);
        // if it is a single digit, make sure it have 0 in front (proper padding)
        if (b <= 0xF)
            m_szUniqueID += "0";
        // add number to string
        m_szUniqueID += Integer.toHexString(b);
    } // hex string to uppercase
    m_szUniqueID = m_szUniqueID.toUpperCase();

    return m_szUniqueID;
}

From source file:Main.java

public static String getWifiName(Context context) {
    Log.v(TAG, "-- Calling WIFI NAME --");
    if (context != null) {
        ConnectivityManager conMgr = (ConnectivityManager) context
                .getSystemService(Context.CONNECTIVITY_SERVICE);
        WifiManager wifiMgr = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
        if (conMgr.getNetworkInfo(ConnectivityManager.TYPE_WIFI).isConnectedOrConnecting()) {
            WifiInfo wifiInfo = wifiMgr.getConnectionInfo();
            Log.v(TAG, "-- WIFI is Enabled Name = " + wifiInfo.getSSID());
            return wifiInfo.getSSID();
        }// www .ja v a  2s. c  o  m
    }
    return "";
}