wifi-direct end connection to peer on Android?

2019-04-28 09:23发布

Is there any way to end the connection to a peer over Wifi-Direct? I tried cancelConnect and removeGroup. Both of them returned Busy? thanks.

1条回答
Root(大扎)
2楼-- · 2019-04-28 09:45

this is the method I am using to disconnect from peer. I noticed from logs that the android built in app also uses the same method to disconnect the peers.

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
                        && group.isGroupOwner()) {
                    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);
                        }
                    });
                }
            }
        });
    }
}
查看更多
登录 后发表回答