Skip to content Skip to sidebar Skip to footer

Wifi Direct Group Owner Address

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.group

Solution 1:

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

  if (networkInfo.isConnected()) {
    wifiP2pManager.requestConnectionInfo(wifiDirectChannel, 
      new ConnectionInfoListener() {
        publicvoidonConnectionInfoAvailable(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

Solution 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.

publicvoidonReceive(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, newConnectionInfoListener() {

                            @OverridepublicvoidonConnectionInfoAvailable(WifiP2pInfo info) {

                                InetAddress groupOwnerAddress = info.groupOwnerAddress;


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

                            }
                        });
                    }
                }
}

Post a Comment for "Wifi Direct Group Owner Address"