p2p connection info null

408 views Asked by At

I've been struggling my way through android studio and specifically p2p and am at a point where I can connect to a Texas Instruments development board or an tablet but cannot get any connection info. I started with WifiP2pInfo as follows,

public void getGroupInfo(View v){

    WifiP2pInfo p2pInfo = new WifiP2pInfo();
    TextView text = (TextView)findViewById(R.id.txtInfo);
    if (p2pInfo.groupFormed){
        text.setText(p2pInfo.groupOwnerAddress.toString());
    }

    else {
        text.setText("no group formed");
    }
}

and got, groupFormed = false, groupOwnerAddress = null, isGroupOwner = false

Then I included a ConnectionInfoListener, implemented as follows,

public class MainActivity extends Activity implements ChannelListener, DeviceActionListener, ConnectionInfoListener{

and override like,

@Override
public void onConnectionInfoAvailable(WifiP2pInfo info) {

    info = new WifiP2pInfo();
    TextView text = (TextView)findViewById(R.id.txtInfo);
    if (info.groupFormed){
        text.setText(info.groupOwnerAddress.toString());
    }

}

but the onConnectionInfoAvailable method never executes. What is the magic to getting connection info? And yes, I am really new to all this, motivated by wanting to control a pneumatic popup target (or 5) from a cell phone over wifi p2p.

Update;

Ok, 18 hours later I found he problem which was simple but elusive. For anyone else that may experience the same torturous ordeal, ConnectionInfoListener will not work without a WifiP2pManager.requestConnectionInfo call. In my case it was implemented as follows;

    else if (WifiP2pManager.WIFI_P2P_CONNECTION_CHANGED_ACTION.equals(action)) {
        //p2p connectivity changed in some way
        NotificationToast.showToast(activity, "connection changed action has triggered");
        manager.requestConnectionInfo(channel, activity);

    }

It is called from my broadcast receiver and activity refers to my main activity where ConnectionInfoListener is implemented.

On to the next headache, cheers!

0

There are 0 answers