5

I an trying to stop peer discovery in wifi direct using the code below.

public void StopPeerDiscovery(){
    manager.stopPeerDiscovery(channel, new ActionListener() {
        @Override
        public void onSuccess() {
            Log.d(WiFiDirectActivity.TAG,"Stopped Peer discovery");
        }

        @Override
        public void onFailure(int i) {
            Log.d(WiFiDirectActivity.TAG,"Not Stopped Peer discovery");
        }
    });
}

I am able to see Success message (Stopped peer discovery) in logs. But other devices are still able to view it in in peer discovery.. Am I doing something wrong here? Please advise. Thanks

Andrea Thacker
  • 3,440
  • 1
  • 25
  • 37
Furious
  • 473
  • 2
  • 5
  • 21
  • I think that's a feature of the API. Basically, you could try if you have same behavior when you turn the Wifi off, or device off. I'm rather sure that the other devices will report seeing it still for a short time. – Dr.Jukka Jul 16 '15 at 06:13
  • i an just not able to see the peers , but also able to connect to it.that is the issue. i don't want other devices to connect once the peer discovery has stopped. – Furious Jul 16 '15 at 14:31
  • Did you try what I suggested ? basically the API is handling the incoming connection as well, thus your app might not have too much to say on it really. Except that it can of course request information on it. – Dr.Jukka Jul 17 '15 at 05:59

1 Answers1

7

This is not an issue. Actually you interpreted this onSuccess wrong. This onSuccess does not tell you that peer discovery has stopped but rather it means that your request has been successfully sent to the hardware/framework responsible for the above call, it will stop discovery asynchronously and let you know (as explained ahead). Similarly, its failure just tells that your call did not reach successfully to the framework.

You need to register a BroadcastReceiver for WIFI_P2P_DISCOVERY_CHANGED_ACTION intent. As you can read in the documentation, the extra namely EXTRA_DISCOVERY_STATE lets you know whether the discovery of peer discovery stopped.

if (WifiP2pManager.WIFI_P2P_DISCOVERY_CHANGED_ACTION.equals(intent.getAction()))
{
    int state = intent.getIntExtra(WifiP2pManager.EXTRA_DISCOVERY_STATE, 10000);
    if (state == WifiP2pManager.WIFI_P2P_DISCOVERY_STARTED)
    {
        // Wifi P2P discovery started.
    }
    else
    {
        // Wifi P2P discovery stopped.
        // Do what you want to do when discovery stopped
    }
}
unrealsoul007
  • 3,809
  • 1
  • 17
  • 33