【问题标题】:WifiP2pManager createGroup and removeGroup are failing with BUSY stateWifiP2pManager createGroup 和 removeGroup 因忙状态而失败
【发布时间】:2015-05-23 21:04:39
【问题描述】:

在我的两台设备上,当我尝试使用WifiP2pManagercreateGroupremoveGroup 时,我得到onFailure 回调,其中2(忙)为reason

我尝试使用此处给出的建议WifiP2pManager return BUSY state on CreateGroup(在创建新组之前删除组),但这没有帮助,因为我总是收到onFailureremoveGroup回调。

我测试过的设备:LG Optimus G (CM 12.1 - Android 5.1)、Gigabyte GSmart Guru G1 (stock Android 4.2)。

更新

代码是:

    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);
        }
    });

【问题讨论】:

  • 您是否还从设置中检查了您的 Wifi 是否已启用?
  • 我不明白您为什么要在 removeGroup 期间尝试创建组?您能解释一下...您是否打算在删除其他组时创建组?

标签: android wifi android-wifi wifi-direct wifip2p


【解决方案1】:

我收到此错误是因为我在组不存在时尝试使用removeGroup。解决方案是在删除或创建新组之前检查当前组是否存在。

这是工作代码(我使用 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);
                }
            });
        }
    });

【讨论】:

    【解决方案2】:

    正如@Dr.Jukka 评论的那样:关闭 wifi 也会导致 BUSY 状态。至少在我的情况下是这样。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-03-15
      • 2019-08-29
      • 2023-02-02
      • 1970-01-01
      • 1970-01-01
      • 2018-05-16
      • 2017-05-05
      • 2022-01-05
      相关资源
      最近更新 更多