Android Context Get getBroadcastAddress(Context context)

Here you can find the source of getBroadcastAddress(Context context)

Description

get Broadcast Address

License

Open Source License

Declaration

public static String getBroadcastAddress(Context context) 

Method Source Code

//package com.java2s;
import java.net.InetAddress;

import java.net.UnknownHostException;

import android.content.Context;
import android.net.DhcpInfo;
import android.net.wifi.WifiManager;

public class Main {
    public static String getBroadcastAddress(Context context) {
        WifiManager wifi = (WifiManager) context
                .getSystemService(Context.WIFI_SERVICE);
        DhcpInfo dhcp = wifi.getDhcpInfo();

        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 {//from w  ww . j av a2s  . c  om
            return InetAddress.getByAddress(quads).getHostAddress();
        } catch (UnknownHostException e) {
            e.printStackTrace();
        }

        return "255.255.255.255";
    }
}

Related

  1. getAsset(@Nonnull Context context, @Nonnull String path)
  2. getAsset(@Nonnull Context context, @Nonnull String path)
  3. getAuthorityFromPermission(Context context, String permission)
  4. getBatteryUsageInfo(Context context)
  5. getBoolean(Context context, String key, boolean defValue)
  6. getCarrier(Context context)
  7. getCertificateFingerprint(Context ctx, String packageName)
  8. getCertificateFromSDCard(Context context)
  9. getChannelNo(Context context)