title: What can fail WifiP2pManager.connect?
body: <p>I have a code that perform a Wifi P2p discovery, presents the nearby devices to the user and let him select to which device he wants to connect.</p>
  
  <p>The discovery is working as expected, but when I try to actually connect to the selected device, the system calls <code>ActionListener.onFailure</code> and passes the reason code for "Internal Error".</p>
  
  <p>This is the code that initiates the connection:</p>
  
  <pre><code>public void connectToDevice(WifiP2pDevice device) {
      Log.i(TAG, "Initiating connection to " + device.deviceAddress);
      stopScan();
      WifiP2pConfig config = new WifiP2pConfig();
      config.deviceAddress = device.deviceAddress;
      config.wps.setup = WpsInfo.PBC;
      // Since we wish to send a friend request, it will be easier if
      // we'll end up as a client because we will have the group owner's
      // address immediately.
      config.groupOwnerIntent = 0;
      mP2pManager.connect(mChannel, config, mConnectionListener);
  }
  </code></pre>
  
  <p>And the <code>mConnectionListener</code> is defined as follows:</p>
  
  <pre><code>protected ActionListener mConnectionListener = new ActionListener() {
      @Override
      public void onSuccess() {
          Log.i(TAG, "Conection initiated successfuly");
      }
  
      @Override
      public void onFailure(int reason) {
          String reasonString = reason(reason);
          Log.e(TAG, "Error while connecting to Wifi peer: " + reasonString);
      }
  };
  </code></pre>
  
  <p>The devices are not part of any group when this error is thrown, and this happens when either device (Nexus 4 &amp; Nexus 7) is the initiator.</p>
  
  <p>Any ideas what might be the problem?</p>