Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
378 views
in Technique[技术] by (71.8m points)

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

When creating a group via Wi-Fi Direct, I know that I can make a persistent group.

My question is: can I create a persistent group, but each time change the group owner (i.e; each turn the group owner will be one of the devices in the group).

Also, when creating a persistent group, it is required to accept the connection only the first time, right?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...