Android examples for android.net.wifi:WifiInfo
get Broadcast Ip
import java.net.InetAddress; import java.net.UnknownHostException; import android.net.wifi.WifiInfo; import android.net.wifi.WifiManager; public class Main { public static WifiManager localWifiManager; private static InetAddress getBroadcastIp() { // Function to return the broadcast address, based on the IP address of the // device/* w w w . jav a2s.co m*/ try { WifiInfo wifiInfo = localWifiManager.getConnectionInfo(); int ipAddress = wifiInfo.getIpAddress(); String addressString = toBroadcastIp(ipAddress); InetAddress broadcastAddress = InetAddress.getByName(addressString); return broadcastAddress; } catch (UnknownHostException e) { return null; } } private static String toBroadcastIp(int ip) { // Returns converts an IP address in int format to a formatted string return (ip & 0xFF) + "." + ((ip >> 8) & 0xFF) + "." + ((ip >> 16) & 0xFF) + "." + "255"; } }