Wifi Direct Group Owner Address

橙三吉。 提交于 2021-02-10 19:57:13

问题


That's an easy question, I've to get the "Group Owner address" using "Wifi direct", I know that this is in WifiP2pInfo.GroupOwnerAddress, but how can I initialize WifiP2pInfo.groupOnwerAddress to get the Group Owner address in my application?

Could someone give me a pass to pass? I'm new in android and java.

Many Thanks.


回答1:


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();    

        }
      }
  }

Sorry for late answer. This is owner IP info.groupOwnerAddress.getHostAddress().toString




回答2:


Group owner IP address in wifi direct is always constant, i.e., 192.168.49.1. To check this, you can make following changes in your BroadcastReceiver class.

   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();                

                            }
                        });
                    }
                }
}


来源:https://stackoverflow.com/questions/15621247/wifi-direct-group-owner-address

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!