NFC + Krautmilen + Android

kraut

We needed to make something to measure timings during the running event Krautmilen.

Equipment:

  1. Make a fugly Android app which could relay runners NFC keyring blips to a server API.
  2. Make a server API to handle the basic running logic (ie pair up names of runners with their start and finish times)

The application is quite simple: once the NFC tag has been blipped it sends an Intent to the application that contains the NDEF data. We grab the ID from the NDEF and perform a HTTP request to the server API.

Since the Android app basically just relays on sending NFC tag IDs to a server, there are lots of use cases, so we released it on Google Play yey! You can enter your own URL, make HTTP requests and use the data to whatever you want. NFC is everywhere nowdays; in travelcards, passports, library books and much more.

Here’s a small code example for handling the Intent:

private void handleIntent(Intent intent) {
      String action = intent.getAction();

      if(NfcAdapter.ACTION_TAG_DISCOVERED.equals(action) || NfcAdapter.ACTION_TECH_DISCOVERED.equals(action) || NfcAdapter.ACTION_NDEF_DISCOVERED.equals(action)) {

            NdefMessage[] messages;
            Parcelable tag = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG);
            getTagData(tag);
      }
}

The only boring thing is that the Android device needs to be unlocked, because the device turns off the NFC chip when it is asleep. This is quite annoying but due to safety reasons it makes sense. You can go around that though, but you will have to root your Android device.

/Johanna