在android wifi direct中设置组所有者

Posted

技术标签:

【中文标题】在android wifi direct中设置组所有者【英文标题】:setting group owner in android wifi direct 【发布时间】:2012-11-02 09:36:30 【问题描述】:

具有更高意图的设备成为组所有者在以下链接中说: http://developer.bada.com/help_2.0/index.jsp?topic=%2Fcom.osp.cppappprogramming.help%2Fhtml%2Fdev_guide%2Fnet%2Fwi-fi_direct_connectivity.htm

我在 wifi-direct 的 google-demo 项目中尝试了以下方法。 在调用广播接收器的主要活动类中,我在一台设备上运行时将优先级设置如下。

public void onResume() 
    super.onResume();
    receiver = new WiFiDirectBroadcastReceiver(manager, channel, this);
    intentFilter.setPriority(999);
    registerReceiver(receiver, intentFilter);

在下一个设备上运行代码时,我没有设置优先级。

public void onResume() 
    super.onResume();
    receiver = new WiFiDirectBroadcastReceiver(manager, channel, this);        
    registerReceiver(receiver, intentFilter);

因此,根据链接,具有较高优先级的设备应该是组所有者,但设置优先级似乎不起作用。 有没有办法在两个设备之间建立连接时将特定设备显式分配为组所有者?

【问题讨论】:

【参考方案1】:

在你的connect方法中设置WifiP2pConfig对象的groupOwnerIntent,取值范围是0到15。 0 表示成为 GO 的倾向最小,15 表示成为 GO 的倾向最高:

WifiP2pConfig 配置 = 新 WifiP2pConfig();

    config.groupOwnerIntent = 0;  //Less probability to become the GO
    config.deviceAddress = service.device.deviceAddress;
    config.wps.setup = WpsInfo.PBC;

【讨论】:

【参考方案2】:

首先,您提供的链接是针对 bada 手机的。我对该操作系统了解不多,但分配可能会有所不同。

无论如何,您可以为您想要的任何设备手动分配意图值。例如,假设您要将单击连接按钮的用户设置为组所有者。根据定义,组所有者应该具有最高的倾向,这意味着大于 0。检查this 链接。

要将同级分配为组所有者,只需将其分配给 15

config.groupOwnerIntent = 15;

【讨论】:

当我使用 config.groupOwnerIntent = 0 连接到远程设备时,这是否意味着我的设备将成为群组所有者或远程设备将成为群组所有者? 由于您的 groupOwnerIntent = 0,您将成为组所有者。但是如果远程设备的 groupOwnerIntent = 0,它将是组所有者。 我认为应该是相反的;见下面feisal的回答。来自文档:This is an integer value between 0 and 15 where 0 indicates the least inclination to be a group owner and 15 indicates the highest inclination to be a group owner. A value of -1 indicates the system can choose an appropriate value. 你是对的。我已经改变了答案。谢谢提醒。【参考方案3】:

当我使用 config.groupOwnerIntent = 0 连接到远程设备时,这是否意味着我的设备将成为组所有者或远程设备将成为组所有者?

如果远程设备的意图值大于 0 ,则您的 config.groupOwnerIntent = 0 设备应该成为客户端。如果两个设备都具有相同的意图值,那么决胜局就会出现。 “intent 值越大,成为 GO 的机会就越大”。我们不能简单地通过将 Intent 值设置为 zer0 来使设备充当组所有者。这也取决于其他连接设备的 Intent 值。

【讨论】:

以上是关于在android wifi direct中设置组所有者的主要内容,如果未能解决你的问题,请参考以下文章

WiFi-Direct 在游戏开发中的使用 (Android)

与 Wifi Direct 的 p2p 连接中的信号强度?

在 Android 和 Raspberry Pi 3 Linux 之间建立 Wifi-Direct 连接

Android 同时运行 Wifi Lan 和 Wifi Direct

WIFI_P2P_CONNECTION_CHANGED_ACTION, Wifi Direct, Android

在 Android WiFi Direct 服务发现中发送数据而不是连接