在 android wifi direct 中设置组所有者

Sub*_*net 2 p2p intentfilter android-intent wifi-direct

具有更高意图的设备成为组所有者在以下链接中说: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);
}
Run Code Online (Sandbox Code Playgroud)

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

public void onResume() {
    super.onResume();
    receiver = new WiFiDirectBroadcastReceiver(manager, channel, this);        
    registerReceiver(receiver, intentFilter);
}
Run Code Online (Sandbox Code Playgroud)

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

fei*_*sal 5

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

WifiP2pConfig config = new WifiP2pConfig();

    config.groupOwnerIntent = 0;  //Less probability to become the GO
    config.deviceAddress = service.device.deviceAddress;
    config.wps.setup = WpsInfo.PBC;
Run Code Online (Sandbox Code Playgroud)