我按照这个文件,使我的Android设备的wifi对等工作:

The link to android wifi p2p document

它's working. I'能够连接和发送数据 . 但我也希望在发现设备时从一开始就跟踪它们的状态 . 问题是,当我的BroadcastReceiver中出现 WIFI_P2P_CONNECTION_CHANGED_ACTION 时,我无法知道哪个设备已连接(或断开连接) . 我需要它在我的设备列表中找到它并更改其状态 .
这是已实现的广播接收器代码的一部分:

public class WiFiDirectBroadcastReceiver extends BroadcastReceiver {
@Override
  public void onReceive(Context context, Intent intent) {
    String action = intent.getAction();
    ...
     if (WifiP2pManager.WIFI_P2P_CONNECTION_CHANGED_ACTION.equals(action)) {
  NetworkInfo networkInfo = intent.getParcelableExtra(WifiP2pManager.EXTRA_NETWORK_INFO);
  Log.d("SERVICESTATUS", "Connection status changed.");
  if (networkInfo.isConnected()) {
    WifiP2pDevice dev = intent.getParcelableExtra(WifiP2pManager.EXTRA_WIFI_P2P_DEVICE); 
    // Here the result is null!!! [dev = null] I want to have its address here

    mP2PManager.requestConnectionInfo(mChannel, info -> {
      // even here there is no information about the address of connected device in 'info' object!!!
    });
  }
} 
...
}

那么,有没有人知道如何在广播接收器中获得有关已更改设备的信息 . 或者是否有更好的方法来跟踪我的设备状态 .

我的要求是拥有一个List,其中包含到目前为止所有已发现的设备,其状态可以是此枚举中的值:

public enum DeviceStatus
{
  Unknown,
  WifiConnecting,
  WifiConnected,
  ReadyForTcpConnection,
  TcpConnecting,
  TcpConnected,
  Authorizing,
  Authorized,
  Idle,
  Error
}

提前谢谢你的帮助 .