首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在Wifi-Direct Android中创建特定的组所有者

如何在Wifi-Direct Android中创建特定的组所有者
EN

Stack Overflow用户
提问于 2013-09-09 17:38:51
回答 2查看 9K关注 0票数 8

我有一个应用程序,将运行在两部手机上。

phone1连接到phone2时,我希望phone1充当clientphone2充当server

我使用了这个代码:

代码语言:javascript
复制
if (info.groupFormed && info.isGroupOwner) {

           // start the server thread

   } else if (info.groupFormed) {

            // start the client thread
   }

但问题是,有时启动连接的phone1 --我希望它充当客户机--有时充当GroupOwner,服务器线程在客户端电话上启动。

我想确保phone2始终充当GroupOwnerserver的角色。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2013-09-09 19:12:22

若要将对等方设置为客户端,而不是每个时间的GroupOWner,我们必须分配:

代码语言:javascript
复制
config.groupOwnerIntent = 0;
票数 13
EN

Stack Overflow用户

发布于 2015-03-16 16:26:59

你能做的就是:

代码语言:javascript
复制
@Override
public void connect(final WifiP2pDevice device) {
    //obtain a peer from the WifiP2pDeviceList
    WifiP2pConfig config = new WifiP2pConfig();
    config.deviceAddress = device.deviceAddress;
    config.wps.setup = WpsInfo.PBC;
    config.groupOwnerIntent = 15; // I want this device to become the owner
    mManager.connect(mChannel, config, new WifiP2pManager.ActionListener() {
        @Override
        public void onSuccess() {
            //success logic
            Log.d(P2P, "connected to device " + device.deviceName);
        }

        @Override
        public void onFailure(int reason) {
            //failure logic
            Log.d(P2P, "unable to establish connection to device " + device.deviceName);
        }
    });
}

注意config.groupOwnerIntent = 15;行。这告诉WifiP2pConfig,我们这个连接的设备更有可能成为GroupOwner。

这里博士

希望能帮上忙。

票数 5
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/18703881

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档