【发布时间】:2020-12-18 05:40:54
【问题描述】:
我正在使用wifiManager.startLocalOnlyHotspot 启动一个无法访问互联网的热点,以便连接设备可以使用套接字将文件发送到此设备。一切都按预期工作,但是当正在 ping 的同一设备的移动数据打开时,我无法 ping 连接的 wifi 热点设备。当我禁用移动数据时,我可以 ping 到从实用程序类获得的 服务器 IP,我正在发布该实用程序方法。谁能向我解释我缺少的概念?
public static String getHotspotIpAddress(Context context) {
WifiManager wifimanager = (WifiManager) context.getApplicationContext().getSystemService(WIFI_SERVICE);
DhcpInfo dhcpInfo = wifimanager == null ? null : wifimanager.getDhcpInfo();
if (dhcpInfo != null) {
int address = dhcpInfo.serverAddress;
return ((address & 0xFF)
+ "." + ((address >> 8) & 0xFF)
+ "." + ((address >> 16) & 0xFF)
+ "." + ((address >> 24) & 0xFF));
}
return "";
}
【问题讨论】:
标签: android android-wifi hotspot personal-hotspot