简体   繁体   English

Reg:连接WiFi Direct设备时IP地址错误?

[英]Reg: Error With IP Address while connecting the WiFi Direct Device?

I was able to connect the WiFi Direct device from Application, While connecting Device is acting as Group Owner and Non-Group Owner. 我能够从应用程序连接WiFi Direct设备,而连接设备同时充当组所有者和非组所有者。 I mainly face this issue in Nexus device. 我主要在Nexus设备上遇到此问题。 After connecting if device act as Group Owner, then wrong IP Address is showing. 连接后,如果设备充当组所有者,则显示错误的IP地址。 This is the code I am using. 这是我正在使用的代码。

WifiP2pConfig config = new WifiP2pConfig();
config.deviceAddress = mPeers.get(arg2).deviceAddress;
config.wps.setup = WpsInfo.PBC;
config.groupOwnerIntent=0;
mWifiP2pManager.connect(mChannel, config, new ActionListener() {
@Override
public void onSuccess() {
    isconnected=true;
}
@Override
public void onFailure(int reason) {
    Toast.makeText(ConfigureNetworkActivity.this, "Connect failed."+reason,
    Toast.LENGTH_SHORT).show();
 }

}); });

I am using this code to retrieve the IP Address. 我正在使用此代码来检索IP地址。 info.groupOwnerAddress.getHostAddress(); info.groupOwnerAddress.getHostAddress(); How we can we retrieve correct IP address, if Device act as Group Owner after connection? 如果设备在连接后充当组所有者,我们如何获取正确的IP地址?

Thanks In Advance. 提前致谢。

By using this code I am able to retrieve the IP Address of Connected WiFi Direct device. 通过使用此代码,我可以检索已连接的WiFi Direct设备的IP地址。 If it is Group Owner. 如果是组所有者。

public static String getIPFromMac(String MAC) {
BufferedReader br = null;
try {
    br = new BufferedReader(new FileReader("/proc/net/arp"));
    String line;
    while ((line = br.readLine()) != null) {

        String[] splitted = line.split(" +");
        if (splitted != null && splitted.length >= 4) {
            // Basic sanity check
            String device = splitted[5];
            if (device.matches(".*p2p-p2p0.*")){
                String mac = splitted[3];
                if (mac.matches(MAC)) {
                    return splitted[0];
                }
            }
        }
    }
} catch (Exception e) {
    e.printStackTrace();
} finally {
    try {
        br.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
}
return null;

} }

Thanks.. 谢谢..

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM