This is an Android library which offers NFC peer-to-peer functionality for Android KitKat devices irrespective of the build-in NFC controller (Broadcom or NXP).
In addition to the Android NFC functionality, this library allows sending larger messages by providing message fragmentation and reassembly. It also makes it possible to use the two-way NFC (Host-based Card Emulation) with NXP devices, since it covers connection disruptions appropriately.
Furthermore, it also supports the ACR122u USB NFC Reader, which can be attached to an Android KitKat device. The user can't decide which NFC controller to use (the interal/build-in or the external ACR122u one). If the ACR122u is plugged in, it will automatically be used once the NfcInitiator
is initialized.
- Java JDK 7
- Eclipse 4.3
- Maven 3.2.1
- Android SDK. In the Android SDK Manager you need to install at least the Android SDK Tools, the Android SDK Platform-tools, and Android 4.4.2 (API 19). For the API 19 the following items are mandatory:
- SDK Platform
- Google APIs
- Glass Development Kit Preview
- Having set up Eclipse according to this guideline.
-
Install two third-party libraries to your local maven repository (read here how to install 3rd party JARs).
- You need the maven-android-sdk-deployer. Follow the instructions there - only platform 4.4 needs to be installed. (This library requires the properties-maven-plugin to be installed to your local maven repository. Otherwise, the installation of maven-android-sdk-deployer will fail.)
- You also need the Android Library for the ACR122u, even if you do not plan to use it in your application. You can download the JAR on the ACS website or from this git repository here.
- Clone this git repository.
- In Eclipse go to
File --> Import --> Maven --> Existing Maven Project
. In the appearing dialog underRoot Directory
enter the path to the checked out project in your git repository. - Select the project AndroidKitKatNFCLibrary and click on
Finish
. - Run
mvn install
on the root folder of this project to install it to your local maven repository. Now you can use this library in your project by adding its groupId, artifactId, and version (see pom.xml) to the POM of your project.
If you want to import this library into your own Android project - without using the AndroidNFCPaymentLibrary - there are three important things that you need to add to your project in order for the NFC to work properly. (See for example the SamplePaymentProject.)
- Copy the file apduservice.xml to
<project root folder>\res\xml\
. - In
<project root folder>\res\values\strings.xml
add the following:
<!-- APDU SERVICE -->
<string name="aiddescription">ch.uzh.csg.nfclib</string>
<string name="servicedesc">Android KitKat NFC Library</string>
- In the
AndroidManifest.xml
add the following:
Inside the<uses-sdk android:minSdkVersion="19" android:targetSdkVersion="19" />
<uses-feature android:name="android.hardware.nfc" android:required="true" />
<uses-permission android:name="android.permission.NFC" />
<application>
tag add:
<service android:name="ch.uzh.csg.nfclib.HostApduServiceNfcLib" android:exported="true" android:permission="android.permission.BIND_NFC_SERVICE">
<intent-filter>
<action android:name="android.nfc.cardemulation.action.HOST_APDU_SERVICE" />
</intent-filter>
<meta-data android:name="android.nfc.cardemulation.host_apdu_service" android:resource="@xml/apduservice" />
</service>
Once this is done, you can use this library in your project by adding its groupId, artifactId, and version (see pom.xml) to the POM of your project.