title: How does Android poll for NFC devices
body: <p>I am working with a contactless reader to communicate with my Android device.</p>
  
  <p>I have observed that any point in time I cannot connect to my Android device using P2P. If I want to connect to initiate an Android Beam transfer I must continuously try to connect to the device multiple times over a one second period.</p>
  
  <p>An NFC Android device can detect contactless cards, NFC P2P targets and NFC P2P initiators i.e. 3 different modes. I am beginning to think that there is some kind of polling going on behind the scenes that switches between the three modes very quickly.</p>
  
  <p>This means that at any given point in time when I try to connect to the phone, it may or may not be in the correct mode and will fail. This is why I need to attempt multiple connections.</p>
  
  <p>I have been looking at the Android source to try and figure this out with no real luck. <a href="https://android.googlesource.com/platform/packages/apps/Nfc/+/android-4.2.1_r1.2/src/com/android/nfc/NfcService.java" rel="noreferrer">here</a> is the most promising file I have seen yet but it still makes no sense.</p>
  
  <p>My question is: How does Android detect multiple NFC modes, does it use a switching algorithm and if so what are the specifics of the algorithm?</p>
  
  <p>Thanks.</p>