Example usage for android.content Context WIFI_SERVICE

List of usage examples for android.content Context WIFI_SERVICE

Introduction

In this page you can find the example usage for android.content Context WIFI_SERVICE.

Prototype

String WIFI_SERVICE

To view the source code for android.content Context WIFI_SERVICE.

Click Source Link

Document

Use with #getSystemService(String) to retrieve a android.net.wifi.WifiManager for handling management of Wi-Fi access.

Usage

From source file:Main.java

public static String getCurrentWifiSSID(Context context) {
    if (context == null) {
        return "";
    }//from   w  w w  . jav  a 2 s .  c om
    WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
    WifiInfo info = wifiManager.getConnectionInfo();
    if (info != null) {
        return info.getSSID() == null ? "" : info.getSSID();
    } else {
        return "";
    }
}

From source file:Main.java

/**
 * Gets the device id./*from  w  w  w . j  a  va2  s  . c om*/
 *
 * @param context the context
 * @return the device id
 */
public synchronized static String getDeviceId(Context context) {
    WifiManager wm = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
    return wm.getConnectionInfo().getMacAddress();
}

From source file:Main.java

public static String getBroadcastAddress(Context context) {
    WifiManager wifi = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
    DhcpInfo dhcp = wifi.getDhcpInfo();/* w  ww.  ja  va  2s.c  o  m*/

    int broadcast = (dhcp.ipAddress & dhcp.netmask) | ~dhcp.netmask;
    byte[] quads = new byte[4];
    for (int k = 0; k < 4; k++)
        quads[k] = (byte) (broadcast >> (k * 8));
    try {
        return InetAddress.getByAddress(quads).getHostAddress();
    } catch (UnknownHostException e) {
        e.printStackTrace();
    }

    return "255.255.255.255";
}

From source file:Main.java

public static String getBroadcastAddress(Context mContext) throws IOException {
    WifiManager wifi = (WifiManager) mContext.getSystemService(Context.WIFI_SERVICE);
    DhcpInfo dhcp = wifi.getDhcpInfo();//w  w  w  . j a v  a  2s . c om
    // handle null somehow

    int broadcast = (dhcp.ipAddress & dhcp.netmask) | ~dhcp.netmask;
    byte[] quads = new byte[4];
    for (int k = 0; k < 4; k++)
        quads[k] = (byte) ((broadcast >> k * 8) & 0xFF);
    return InetAddress.getByAddress(quads).getHostAddress().toString();
}

From source file:Main.java

public static List<WifiConfiguration> getHotspotsList(Context context) {
    final WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
    if (wifiManager == null)
        return new ArrayList<WifiConfiguration>();
    return wifiManager.getConfiguredNetworks();
}

From source file:Main.java

/**
 * network tools/*from  ww w.  ja va  2  s  .  c om*/
 * */
public static boolean isWifiEnable(Context context) {

    WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);

    Log.i(TAG, "wifiEnable" + wifiManager.isWifiEnabled());
    return wifiManager.isWifiEnabled();
}

From source file:Main.java

/**
 * @param ctx//w  w w. j  ava  2s . co m
 *         The {@link context}.
 * 
 * @return A {@link String} representing the device's MAC address
 */

public static String getDeviceId(Context ctx) {
    WifiManager wm = (WifiManager) ctx.getSystemService(Context.WIFI_SERVICE);
    String wmac = wm.getConnectionInfo().getMacAddress();
    return wmac;
}

From source file:Main.java

public static WifiManager getWifiManager(Context context) {
    return (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
}

From source file:Main.java

public static InetAddress getBroadcastAddress(Context context) throws UnknownHostException {
    WifiManager wifi = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
    DhcpInfo dhcp = wifi.getDhcpInfo();//from  w ww .  ja  v a2s. com
    if (dhcp == null) {
        return InetAddress.getByName("255.255.255.255");
    }
    int broadcast = (dhcp.ipAddress & dhcp.netmask) | ~dhcp.netmask;
    byte[] quads = new byte[4];
    for (int k = 0; k < 4; k++)
        quads[k] = (byte) ((broadcast >> k * 8) & 0xFF);
    return InetAddress.getByAddress(quads);
}

From source file:Main.java

public static String getMacAddress(Context context) {
    WifiManager wifi = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
    WifiInfo info = wifi.getConnectionInfo();
    String macAddress = info.getMacAddress().replace(":", "");
    return macAddress == null ? "" : macAddress;
}