查看androidwifip2p连接是否成功?
Check whether android wifip2p connection was successful?
我正在通过 Wifi Direct 连接两个 android 设备。我在第一台设备上使用 Wifip2pManager.createGroup 创建了一个组。
现在,我在第二台设备上调用 Wifip2pManager.connect 方法。但是连接方法是成功的,即使第一个设备拒绝连接,因为它只检查是否成功初始化。如何检查其他设备是否接受连接?
class需要实现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 台设备之间发送图像。检查它的实现并尝试在它之上构建。 Link: http://developer.android.com/guide/topics/connectivity/wifip2p.html
希望这对您有所帮助。如果您有任何问题,请告诉我。
我正在通过 Wifi Direct 连接两个 android 设备。我在第一台设备上使用 Wifip2pManager.createGroup 创建了一个组。
现在,我在第二台设备上调用 Wifip2pManager.connect 方法。但是连接方法是成功的,即使第一个设备拒绝连接,因为它只检查是否成功初始化。如何检查其他设备是否接受连接?
class需要实现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 台设备之间发送图像。检查它的实现并尝试在它之上构建。 Link: http://developer.android.com/guide/topics/connectivity/wifip2p.html
希望这对您有所帮助。如果您有任何问题,请告诉我。