Can I change the group owner in a persistent group in Wi-Fi Direct?

删除回忆录丶 提交于 2019-11-27 04:18:24
Bill G

You can now create a new persistent group via WifiP2pManager.createGroup(..). It will create a new group and make the calling device (A) group owner and can do what you described. The only problem is once you create a group and connect to another device, that other device (B) will remember that specific group. If you try to create a new group in A (say, opening the app a second time) and try to connect from B, it will automatically join the old group and not appear as if it is connected in the new group in A.

EDIT: There is a way to wipe out all persistent groups. It is a hidden function called deletePersistentGroups. This will wipe out every single one though, but it seems to be the only reliable way to solve your problem. Call this after you call WifiP2pManager.initialize(..), so you can use the channel.

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(wifiP2pManager, mChannel, netid, null);
                }
            }
        }
    } catch(Exception e) {
        e.printStackTrace();
    }
}

I'm not quite sure why the netid goes up to 31, I would assume that that is the maximum number of allowed remembered connections. Code taken from here.

The answer for your first question is NO. "The P2P Group Owner of a Persistent P2P Group is determined when the P2P Group is formed and is the same P2P Device in subsequent P2P Group sessions." This line from the p2p specification says that you cant' change the group owner.

Yes, it is required to accept the connect just in the first time.A persistent group allows reconnection without user intervention.

The persistence behaviour is not supported yet in android wifi direct framework.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!