1

这是一个简单的问题,我必须使用“Wifi direct”获取“组所有者地址”,我知道这是在 WifiP2pInfo.GroupOwnerAddress 中,但是如何初始化 WifiP2pInfo.groupOnwerAddress 以在我的应用程序中获取组所有者地址?

有人可以给我通行证吗?我是android和java的新手。

非常感谢。

4

2 回答 2

3
NetworkInfo networkInfo = (NetworkInfo)intent.getParcelableExtra(extraKey);

  if (networkInfo.isConnected()) {
    wifiP2pManager.requestConnectionInfo(wifiDirectChannel, 
      new ConnectionInfoListener() {
        public void onConnectionInfoAvailable(WifiP2pInfo info) { 


            Toast toast=Toast.makeText(class.this,info.groupOwnerAddress.getHostAddress().toString, Toast.LENGHT_SHORT); 
            toast.show();    

        }
      }
  }

对不起,迟到的答案。这是所有者 IPinfo.groupOwnerAddress.getHostAddress().toString

于 2013-07-05T22:32:30.887 回答
2

wifi direct 中的群主IP 地址始终是不变的,即192.168.49.1。要检查这一点,您可以在 BroadcastReceiver 类中进行以下更改。

   public void onReceive(Context context, Intent intent) {
                String action = intent.getAction();

        if (WifiP2pManager.WIFI_P2P_CONNECTION_CHANGED_ACTION.equals(action)) {

                    if (mManager == null) {
                        return;
                    }
                    NetworkInfo networkInfo = (NetworkInfo) intent
                            .getParcelableExtra(WifiP2pManager.EXTRA_NETWORK_INFO);


                    if (networkInfo.isConnected()) {

                        mManager.requestConnectionInfo(mChannel, new ConnectionInfoListener() {

                            @Override
                            public void onConnectionInfoAvailable(WifiP2pInfo info) {

                                InetAddress groupOwnerAddress = info.groupOwnerAddress;


                                String s=groupOwnerAddress.getHostAddress();
                                Toast.makeText(mActivity, "Server IP Address "+s, Toast.LENGTH_SHORT).show();                

                            }
                        });
                    }
                }
}
于 2014-06-03T05:34:18.673 回答