BlueMountain
BlueMountain

Reputation: 247

WIFI P2P REMOVE GROUP

I want to connect from one device to different devices one by one. So what I do is check if my device is connected if(myDevice.status == 0) and if so, I remove the group manager.removeGroup(channel, new ActionListener().

The problem here is that after a couple of times doing this, the method removeGroup() goes to onFailure() with this error: Disconnect failed. Reason :2 which means "BUSY".

How can I stop the framework from being BUSY? Is there any proper way of disconnection between two devices in order to start a new connection to a different one without any problem?

Upvotes: 4

Views: 2537

Answers (1)

Ankit Mundada
Ankit Mundada

Reputation: 417

Wifi P2p creates a persistent group every time it creates a new group. So just removeGroup() won't work. You will have to use DeletePersistantGroup method (which is hidden). Use reflection to invoke a call on this method:

    private void deletePersistentGroups(){
    try {
        Method[] methods = WifiP2pManager.class.getMethods();
        for (int i = 0; i < methods.length; i++) {
            if (methods[i].getName().equals("deletePersistentGroup")) {
                // Delete any persistent group
                for (int netid = 0; netid < 32; netid++) {
                    methods[i].invoke(manager, channel, netid, null);
                }
            }
        }
    } catch(Exception e) {
        e.printStackTrace();
    }
}

Upvotes: 3

Related Questions