0
내가 와이파이 다이렉트를 사용하여 하나 개의 무선 랜 장치에 연결을 시도

를 호출 성공 콜백을 연결하지만 난 다음 코드를 실행하면 항상 내가 여기에 실수 을 만들어 내 코드안드로이드 와이파이 다이렉트를 반복

입니다 연결된 장치의 통지가 무한 내가 아는 수 있습니다 보여 있어요
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

사용

for ( WifiP2pDevice peer : peers.getDeviceList()) { 
대신에

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

관련 문제