android - 如何在 Wifi Direct 中创 build 备组所有者?

标签 android wifi-direct

我开发了一个 WiFi Direct 应用程序,我使用此代码来区分 groupOwner 和其他设备。但是 groupOwner 总是随机生成的。我想确保每次建立连接时连接设备都像 groupOwner 一样。我的代码:

if (info.groupFormed && info.isGroupOwner) {

     // GroupOwner     

   } else if (info.groupFormed) {


   } 

最佳答案

如果您的目标是让正在广告服务的设备也是群组所有者,那么在您的 WifiP2pManager 实例上调用 onSuccess 中的 createGroup addLocalService

的回调
WifiP2pManager manager = (WifiP2pManager) getSystemService(Context.WIFI_P2P_SERVICE);
WifiP2pManager.Channel channel = serverManager.initialize(this, getMainLooper(), null);

HashMap<String, String> record = new HashMap<String, String>();

WifiP2pServiceInfo serviceInfo = WifiP2pDnsSdServiceInfo.newInstance("_hello", "_world._tcp", record);

//remove legacy group
manager.removeGroup(channel, null);

//advertise your service
manager.addLocalService(channel, serviceInfo, new WifiP2pManager.ActionListener() {

  @Override
  public void onFailure(int reason) {
  }

  @Override
  public void onSuccess() {
    //create group, making this device the owner of the group
    manager.createGroup(channel, null);
  }

});

关于android - 如何在 Wifi Direct 中创 build 备组所有者?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19318291/

相关文章:

java - 获取特定位置java上的字符串文本或编辑文本

android - 如何在 Android 原生应用中添加 Power BI 报表

android - 未找到改造注释。 (参数#1)

android直接移植wifi

Android 无线直连 : How to send data from Group Owner to the clients?

java - Android CookieManager

java - tools.jar 似乎不在 Windows 8 上的 Android Studio 类路径中

Android WiFi-Direct : discovering, 连接问题。详细讨论

android - WiFi-Direct Api 和 Alljoyn 框架的区别

android - Android 平台上使用 wifi-direct 的客户端/对等方通信