Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Peer connection failure #8

Open
punittt opened this issue Sep 3, 2018 · 3 comments
Open

Peer connection failure #8

punittt opened this issue Sep 3, 2018 · 3 comments

Comments

@punittt
Copy link

punittt commented Sep 3, 2018

My code keeps going to onPeerConnectionFailure() calback.
Here it is -

` private WifiP2PServiceImpl wifiP2PService;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    wifiP2PService = new WifiP2PServiceImpl.Builder()
            .setSender(this)
            .setWifiP2PConnectionCallback(this)
            .build();
    wifiP2PService.onCreate();
}

@Override
public void onInitiateDiscovery() {
    Log.d("*****", "initiate discovery");
}

@Override
public void onDiscoverySuccess() {
    Log.d("*****", "discovery success");

}

@Override
public void onDiscoveryFailure() {
    Log.d("*****", "discovery failure");

}

@Override
public void onPeerAvailable(WifiP2pDeviceList wifiP2pDeviceList) {
    Log.d("*****", "peer available");

    ArrayList<WifiP2pDevice> devices = new ArrayList<>(wifiP2pDeviceList.getDeviceList());

    for(int i=0; i<devices.size(); i++){
        if(devices.get(i).deviceName.equals("Smart TV"))
            wifiP2PService.connectDevice(devices.get(i));
    }
}

@Override
public void onPeerStatusChanged(WifiP2pDevice wifiP2pDevice) {
    Log.d("*****", "peer status change");

}

@Override
public void onPeerConnectionSuccess() {
    wifiP2PService.startDataTransfer("Helllooo");
    Log.d("*****", "peer connection success");

}

@Override
public void onPeerConnectionFailure() {
    Log.d("*****", "peer connection failure");

}

@Override
public void onPeerDisconnectionSuccess() {
    Log.d("*****", "peer disconnection success");

}

@Override
public void onPeerDisconnectionFailure() {
    Log.d("*****", "peer disconnection failure");

}

@Override
public void onDataTransferring() {
    Log.d("*****", "data transferring");

}

@Override
public void onDataTransferredSuccess() {
    Log.d("*****", "data transferring success");

}

@Override
public void onDataTransferredFailure() {
    Log.d("*****", "data transferring failure");

}

@Override
public void onDataReceiving() {
    Log.d("*****", "data receiving");

}

@Override
public void onDataReceivedSuccess(String s) {
    Log.d("*****", "data receiving success");

}

@Override
public void onDataReceivedFailure() {
    Log.d("*****", "data receiving failure");

}

@Override
protected void onResume() {
    super.onResume();
    wifiP2PService.onResume();
}

@Override
protected void onStop() {
    super.onStop();
    wifiP2PService.onStop();
}`

Here is my receiver app code -

` private WifiP2PServiceImpl wifiP2PService;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    wifiP2PService = new WifiP2PServiceImpl.Builder()
            .setReceiver(this)
            .setWifiP2PConnectionCallback(this)
            .build();
    wifiP2PService.onCreate();
}

@Override
public void onInitiateDiscovery() {
    Log.d("*****", "initiate discovery");
}

@Override
public void onDiscoverySuccess() {
    Log.d("*****", "discovery success");

}

@Override
public void onDiscoveryFailure() {
    Log.d("*****", "discovery failure");

}

@Override
public void onPeerAvailable(WifiP2pDeviceList wifiP2pDeviceList) {
    Log.d("*****", "peer available");

}

@Override
public void onPeerStatusChanged(WifiP2pDevice wifiP2pDevice) {
    Log.d("*****", "peer status change");

}

@Override
public void onPeerConnectionSuccess() {
    Log.d("*****", "peer connection success");

}

@Override
public void onPeerConnectionFailure() {
    Log.d("*****", "peer connection failure");

}

@Override
public void onPeerDisconnectionSuccess() {
    Log.d("*****", "peer disconnection success");

}

@Override
public void onPeerDisconnectionFailure() {
    Log.d("*****", "peer disconnection failure");

}

@Override
public void onDataTransferring() {
    Log.d("*****", "data transferring");

}

@Override
public void onDataTransferredSuccess() {
    Log.d("*****", "data transferring success");

}

@Override
public void onDataTransferredFailure() {
    Log.d("*****", "data transferring failure");

}

@Override
public void onDataReceiving() {
    Log.d("*****", "data receiving");

}

@Override
public void onDataReceivedSuccess(String s) {
    Toast.makeText(MainActivity.this, s, Toast.LENGTH_SHORT).show();
    Log.d("*****", "data receiving success");
}

@Override
public void onDataReceivedFailure() {
    Log.d("*****", "data receiving failure");

}

@Override
protected void onResume() {
    super.onResume();
    wifiP2PService.onResume();
}

@Override
protected void onStop() {
    super.onStop();
    wifiP2PService.onStop();
}

`
Can you help me with the reason behind it?

@bhavin42
Copy link

same issue

@AadarshaSadan
Copy link

i got same issue

@spacekookie
Copy link

I have the same issue. I think the Android WifiP2p APIs changed quite a bit in the last 2 years. I had a prototype for this sort of stuff working in 2018 but now it doesn't anymore.

It's especially confusing to me how initiateDiscovery() is never called by the app code. The version on the play store is working, but I'm wondering if that's because it's linking against older android libs...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants