gpt4 book ai didi

android - 查看android wifip2p连接是否成功?

转载 作者:太空狗 更新时间:2023-10-29 13:20:41 27 4
gpt4 key购买 nike

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

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

最佳答案

该类需要实现ConnectionInfoListener。在函数 onConnectionInfoAvailable(final WifiP2pInfo info) 中,您可以检查是否已成功建立连接。 WifiP2pInfo 类型的 info 参数包含有关连接的信息。它包含一个名为 groupFormed 的 bool 值,它指示是否已成功形成 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

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

关于android - 查看android wifip2p连接是否成功?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29445560/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com