本文整理匯總了Java中android.net.wifi.WifiManager.getDhcpInfo方法的典型用法代碼示例。如果您正苦於以下問題:Java WifiManager.getDhcpInfo方法的具體用法?Java WifiManager.getDhcpInfo怎麽用?Java WifiManager.getDhcpInfo使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.net.wifi.WifiManager
的用法示例。
在下文中一共展示了WifiManager.getDhcpInfo方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getBroadcastAddress
import android.net.wifi.WifiManager; //導入方法依賴的package包/類
public static InetAddress getBroadcastAddress(Context c) throws UnknownHostException {
WifiManager wifi = (WifiManager) c.getSystemService(Context.WIFI_SERVICE);
DhcpInfo dhcp = wifi.getDhcpInfo();
if (dhcp == null) {
return InetAddress.getByAddress(null);
}
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);
}
示例2: getGatewayIP
import android.net.wifi.WifiManager; //導入方法依賴的package包/類
private String getGatewayIP() {
if (!checkIsWifiOnAndConnected()) return "0.0.0.0";
WifiManager wifi = (WifiManager) getApplicationContext().getSystemService(WIFI_SERVICE);
DhcpInfo dhcp = wifi.getDhcpInfo();
int ip = dhcp.gateway;
return String.format("%d.%d.%d.%d",
(ip & 0xff),
(ip >> 8 & 0xff),
(ip >> 16 & 0xff),
(ip >> 24 & 0xff)
);
}
示例3: getRouterIp
import android.net.wifi.WifiManager; //導入方法依賴的package包/類
public static String getRouterIp(Context context){
WifiManager wifiService = (WifiManager) context.getApplicationContext().getSystemService(Context.WIFI_SERVICE);
if(wifiService == null){
return null;
}
DhcpInfo dhcpInfo = wifiService.getDhcpInfo();
return Formatter.formatIpAddress(dhcpInfo.gateway);
}
示例4: getGatewayIpAddress
import android.net.wifi.WifiManager; //導入方法依賴的package包/類
public static void getGatewayIpAddress(Context c) {
// get wifi ip
final WifiManager manager = (WifiManager) c.getSystemService(Context.WIFI_SERVICE);
final DhcpInfo dhcp = manager.getDhcpInfo();
final String address = Formatter.formatIpAddress(dhcp.gateway);
StringBuilder IFCONFIG = new StringBuilder();
try {
for (Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces(); en.hasMoreElements(); ) {
NetworkInterface intf = en.nextElement();
for (Enumeration<InetAddress> enumIpAddr = intf.getInetAddresses(); enumIpAddr.hasMoreElements(); ) {
InetAddress inetAddress = enumIpAddr.nextElement();
if (!inetAddress.isLoopbackAddress() && !inetAddress.isLinkLocalAddress()
&& inetAddress.isSiteLocalAddress()) {
IFCONFIG.append(inetAddress.getHostAddress().toString() + "\n");
}
}
}
} catch (SocketException ex) {
Log.e("LOG_TAG", ex.toString());
}
MLog.d(TAG, "ifconfig " + IFCONFIG.toString());
MLog.d(TAG, "hotspot address is " + address);
}