我可以在Wi-Fi Direct的永久组中更改组所有者吗? [英] Can I change the group owner in a persistent group in Wi-Fi Direct?

查看:177
本文介绍了我可以在Wi-Fi Direct的永久组中更改组所有者吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通过Wi-Fi Direct创建群组时,我知道我可以创建一个永久群组.

我的问题是:我可以创建一个持久性组,但是每次更改组所有者(即每次旋转时,该组所有者将成为该组中的设备之一).

此外,在创建持久组时,需要仅在第一次时接受连接,对吗?

解决方案

您现在可以通过WifiP2pManager.createGroup(..)创建一个新的持久性组.它将创建一个新的组,并使呼叫设备(A)成为组的所有者,并可以执行您描述的操作.唯一的问题是,一旦创建一个组并连接到另一台设备,该另一台设备(B)就会记住该特定组.如果您尝试在A中创建一个新组(例如,第二次打开该应用程序)并尝试从B连接,它将自动加入旧组,而不是好像已连接到A中的新组./p>

有一种方法可以消灭所有持久性组.这是一个名为deletePersistentGroups的隐藏函数.尽管这将消灭每一个问题,但这似乎是解决问题的唯一可靠方法.呼叫WifiP2pManager.initialize(..)后再调用此按钮,以便可以使用频道.

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

我不太确定netid为何会升至31,我认为那是允许记住的最大连接数.代码来自这里.

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?

解决方案

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.

这篇关于我可以在Wi-Fi Direct的永久组中更改组所有者吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆