2

On both of my devices when I try to use WifiP2pManager's createGroup or removeGroup I get the onFailure callback with 2 (BUSY) as reason.

I've tried to use suggestion given here WifiP2pManager return BUSY state on CreateGroup (removing group before creating a new one), but it didn't help because I'm always getting onFailure callback in removeGroup.

Devices I tested on: LG Optimus G (CM 12.1 - Android 5.1), Gigabyte GSmart Guru G1 (stock Android 4.2).

UPDATE

The code is:

    manager.removeGroup(channel, new WifiP2pManager.ActionListener() {
        @Override
        public void onSuccess() {
            Debug.d();

            manager.createGroup(channel, new WifiP2pManager.ActionListener() {
                @Override
                public void onSuccess() {
                    Debug.d();
                }

                @Override
                public void onFailure(int reason) {
                    Debug.d("" + reason);
                }
            });
        }

        @Override
        public void onFailure(int reason) {
            Debug.d("" + reason);
        }
    });
Community
  • 1
  • 1
s0nerik
  • 681
  • 2
  • 7
  • 14
  • 1
    have you also checked that your Wifi is enabled from the settings ? – Dr.Jukka May 25 '15 at 05:36
  • I don't understand why you are trying to createGroup during removeGroup? Can you explain that... Do you intend to createGroup when some other group has been removed? – unrealsoul007 May 25 '15 at 06:26

2 Answers2

1

I was getting this error because I tried to use removeGroup when group didn't exist. The solution is to check whether the current group exist before removing it or creating a new one.

Here's the working code (I use Retrolambda):

    manager.requestGroupInfo(channel, group -> {
        if (group != null) {
            Debug.d("group != null");
            manager.removeGroup(channel, new WifiP2pManager.ActionListener() {
                @Override
                public void onSuccess() {
                    Debug.d();

                    manager.createGroup(channel, new WifiP2pManager.ActionListener() {
                        @Override
                        public void onSuccess() {
                            Debug.d();
                        }

                        @Override
                        public void onFailure(int reason) {
                            Debug.d("" + reason);
                        }
                    });
                }

                @Override
                public void onFailure(int reason) {
                    Debug.d("" + reason);
                }
            });
        } else {
            manager.createGroup(channel, new WifiP2pManager.ActionListener() {
                @Override
                public void onSuccess() {
                    Debug.d();
                }

                @Override
                public void onFailure(int reason) {
                    Debug.d("" + reason);
                }
            });
        }
    });
s0nerik
  • 681
  • 2
  • 7
  • 14
0

As @Dr.Jukka commented: Having the wifi turned off, can also cause a BUSY state. That was at least in my case.

crgarridos
  • 8,758
  • 3
  • 49
  • 61