0

я пытаюсь подключиться к одной Wi-Fi устройства с помощью wifidirect, но когда я запускаю следующий код он всегда показывает подключенное устройство уведомления бесконечно может я знаю, где я сделал ошибку Вот мой фрагмент кодаандроид wifidirect подключения успеха обратного вызова вызова неоднократно

if (WifiP2pManager.WIFI_P2P_PEERS_CHANGED_ACTION.equals(action)) { 
    final Context ctx = context; 
    //showing this pop up message always can you help me to understand this issue please 
    Toast.makeText(ctx, "WIFI_P2P_PEERS_CHANGED_ACTION",Toast.LENGTH_LONG).show(); 
    if (mManager != null) { 

     mManager.requestPeers(mChannel, new WifiP2pManager.PeerListListener() { 

       @Override 
       public void onPeersAvailable(WifiP2pDeviceList peers) { 

        for ( WifiP2pDevice peer : peers.getDeviceList()) { 

         WifiP2pDevice device=peer; 
         String serverName = "Android_f9c4"; 
         if(device.deviceName.equals(serverName)){ 
          WifiP2pConfig config = new WifiP2pConfig(); 
          config.deviceAddress = device.deviceAddress; 


          mManager.connect(mChannel,config ,new ActionListener() { 

          //whats wrong here 
           @Override 
           public void onSuccess() { 
            // This fire always 
            Toast.makeText(ctx, "connected",Toast.LENGTH_LONG).show(); 
           } 

           @Override 
           public void onFailure(int reason) { 
            // TODO Auto-generated method stub 
            Toast.makeText(ctx, "Not connected",Toast.LENGTH_LONG).show(); 
           } 

          }); 
         } 

        } 

       } 
      }); 
     } 

    } 
} 

ответ

0

использование

ArrayList<WifiP2pDevice> list=peers.getDeviceList(); 
for(WifiP2pDevice peer : list) 

вместо

for ( WifiP2pDevice peer : peers.getDeviceList()) {