【问题标题】:Check whether android wifip2p connection was successful?检查android wifip2p连接是否成功?
【发布时间】:2015-04-04 10:54:58
【问题描述】:

我正在通过 Wifi Direct 连接两个安卓设备。我在第一台设备上使用 Wifip2pManager.createGroup 创建了一个组。

现在,我在第二台设备上调用 Wifip2pManager.connect 方法。但是连接方法是成功的,即使第一个设备拒绝连接,因为它只检查成功的初始化。如何检查其他设备是否接受了连接?

【问题讨论】:

  • 如果我的解决方案有帮助,请点赞我,以便其他人从中受益。如果没有,让我知道是什么问题。

标签: android wifi-direct


【解决方案1】:

该类需要实现ConnectionInfoListener。在onConnectionInfoAvailable(final WifiP2pInfo info) 函数中,您可以检查是否已成功建立连接。 WifiP2pInfo 类型的 info 参数包含有关连接的信息。它包含一个名为groupFormed 的布尔值,它指示p2p 组是否已成功形成。如果设备是groupOwner和groupOwner的IP等,也可以从中检索。

@Override
    public void onConnectionInfoAvailable(final WifiP2pInfo info) {

        // After the group negotiation, we check if this device 
        // is acting as group owner

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

            // Do whatever you want the group owner to do

        } else if (info.groupFormed) {
            // The device now act as the slave device, 
            // and the other connected device is group owner
    }

Google 提供了一个非常好的演示应用程序,它使用 WiFi Direct 在 2 个设备之间发送图像。检查它的实现并尝试在它之上构建。链接:http://developer.android.com/guide/topics/connectivity/wifip2p.html

希望这会有所帮助。如果您有任何问题,请告诉我。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-10-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-07-04
    • 1970-01-01
    • 2017-11-06
    相关资源
    最近更新 更多