आप दोनों सहकर्मियों के स्थानीय आईपी पते ला सकते हैं और समूह के मालिक आईपी के साथ तुलना कर सकते हैं। आप पहले से ही पता हो सकता है आप आसानी से कोड की इस पंक्ति के साथ समूह के स्वामी आईपी प्राप्त कर सकते हैं:
: नीचे संबंधित विधियों के साथ
localIp = getDottedDecimalIP(getLocalIPAddress());
:
WifiP2pInfo.info.groupOwnerAddress.getHostAddress();
स्थानीय IP के लिए आप बस इस का उपयोग कर सकते
private byte[] getLocalIPAddress() {
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()) {
if (inetAddress instanceof Inet4Address) {
return inetAddress.getAddress();
}
}
}
}
} catch (SocketException ex) {
// Log.e("AndroidNetworkAddressFactory", "getLocalIPAddress()", ex);
} catch (NullPointerException ex) {
// Log.e("AndroidNetworkAddressFactory", "getLocalIPAddress()", ex);
}
return null;
}
private String getDottedDecimalIP(byte[] ipAddr) {
if (ipAddr != null) {
String ipAddrStr = "";
for (int i = 0; i < ipAddr.length; i++) {
if (i > 0) {
ipAddrStr += ".";
}
ipAddrStr += ipAddr[i] & 0xFF;
}
return ipAddrStr;
} else {
return "null";
}
}
क्या आपको उत्तर मिल गया ???? यदि हां, कृपया साझा करें, मुझे इसकी आवश्यकता है। –