【问题标题】:wifi-direct end connection to peer on Android?wifi-direct端连接到Android上的对等点?
【发布时间】:2013-09-08 01:19:58
【问题描述】:

有什么方法可以结束通过 Wifi-Direct 与对等方的连接? 我试过cancelConnect和removeGroup。两人都回忙了?谢谢。

【问题讨论】:

    标签: android wifi-direct service-discovery


    【解决方案1】:

    这是我用来与对等方断开连接的方法。我从日志中注意到,android 内置应用程序也使用相同的方法断开对等点的连接。

    public static void disconnect() {
        if (mManager != null && mChannel != null) {
            mManager.requestGroupInfo(mChannel, new GroupInfoListener() {
                @Override
                public void onGroupInfoAvailable(WifiP2pGroup group) {
                    if (group != null && mManager != null && mChannel != null) {
                        mManager.removeGroup(mChannel, new ActionListener() {
    
                            @Override
                            public void onSuccess() {
                                Log.d(TAG, "removeGroup onSuccess -");
                            }
    
                            @Override
                            public void onFailure(int reason) {
                                Log.d(TAG, "removeGroup onFailure -" + reason);
                            }
                        });
                    }
                }
            });
        }
    }
    

    2020 年 1 月 12 日编辑:从 if 语句中删除了 isGroupOwner()。这允许非所有者设备使用相同的方法断开连接。

    当非所有者断开连接时,新的 WifiP2pInfo 将显示:

    groupFormed: false isGroupOwner: false groupOwnerAddress: null

    您可以从以下位置找到您的 WifiP2pInfo:

    (1)注册一个广播接收器监听WIFI_P2P_CONNECTION_CHANGED_ACTION并从额外的EXTRA_WIFI_P2P_INFO获取WifiP2pInfo

    (2) 致电WifiP2pManager#requestConnectionInfo

    【讨论】:

    • 如果你不是群主,有没有办法断开连接?
    猜你喜欢
    • 2018-11-01
    • 1970-01-01
    • 2012-12-05
    • 1970-01-01
    • 1970-01-01
    • 2012-09-22
    • 2012-11-03
    • 1970-01-01
    • 2023-03-12
    相关资源
    最近更新 更多