title: Where should an NFC timeout be handled?
body: <p>I need to return to a server a specific return code in the case of a NFC timeout in an android application.</p>
  <p>I have found the documentation for the setting a timeout, however I cant find documentation about how this timeout should/can be handled if it occurs.</p>
  <p><a href="https://developer.android.com/reference/android/nfc/tech/IsoDep#getTimeout()" rel="nofollow noreferrer">https://developer.android.com/reference/android/nfc/tech/IsoDep#getTimeout()</a></p>
  <p>Where should the timeout itself be handled , is it an exception or is there a method that should be overridden?</p>
  <pre><code>private boolean ConnectToTag(@NonNull IsoDep isoDep) {
  
      if (!isoDep.isConnected()) {
  
          try {
  
              isoDep.connect();
              isoDep.setTimeout(5000);
  
          }  catch (Exception e) {
  
              HyperLog.e(TAG, &quot;Could not connect to tag&quot;, e);
              onNFCException(SIM.TRANSMISSION_ERROR);
              return false;
          }
  
      }
      return true;
  </code></pre>
  <p>}</p>
  <pre><code>@Nullable
  public byte[] Transceive(byte[] apdu) {
  
  
      try {
          if (!isoDep.isConnected()) {
              boolean connected = ConnectToTag(isoDep);
          }
          if (isoDep.isConnected()) {
  
              byte[] response;
              HyperLog.i(TAG, &quot;NFC =&gt; &quot; + ByteUtils.BytesToHexString(apdu));
             
              response = isoDep.transceive(apdu);
             
  
              if (response == null) {
                  HyperLog.i(TAG, &quot;NFC &lt;= null&quot;);
              } else {
                  HyperLog.i(TAG, &quot;NFC &lt;= &quot; + ByteUtils.BytesToHexString(response));
                  return response;
              }
  
          } else {
              HyperLog.e(TAG, &quot;Transceive() - Tag disconnected.&quot;);
          }
  
      } catch (TagLostException e) {
          HyperLog.e(TAG, &quot;Transceive() - Error transceiving data&quot;, e);
          onNFCException(SIM.TRANSMISSION_ERROR);
      }
  }
  </code></pre>