NfcReactNative
nfc-ndef-react-native is a react-native module for android to write/read tags that support the NDEF format (tested on Mifare Classic). This is a fork of Lube's nfc-react-native. WIP.
Getting started
$ npm install nfc-ndef-react-native --save
Mostly automatic installation
$ react-native link nfc-ndef-react-native
Manual installation
Android
- Open up
android/app/src/main/java/[...]/MainApplication.java
- Add
import es.tiarg.nfcreactnative.NfcReactNativePackage;
to the imports at the top of the file - Add
new NfcReactNativePackage()
to the list returned by the getPackages()
method
- Append the following lines to
android/settings.gradle
:
include ':nfc-react-native'
project(':nfc-react-native').projectDir = new File(rootProject.projectDir, '../node_modules/nfc-react-native/android')
- Insert the following lines inside the dependencies block in
android/app/build.gradle
:
compile project(':nfc-react-native')
Usage
Take a look at the example.
Configuration
In your manifest add:
<uses-permission android:name="android.permission.NFC" />
....
Your main activity should look like
...
<activity
android:name=".MainActivity"
android:launchMode="singleTask"
android:label="@string/app_name"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize">
<intent-filter>
<action android:name="android.nfc.action.TECH_DISCOVERED"/>
</intent-filter>
<meta-data android:name="android.nfc.action.TECH_DISCOVERED"
android:resource="@xml/nfc_tech_filter" />
</activity>
Add android/app/src/main/res/xml/nfc_tech_filter.xml (create directories that don't exist) with the following:
<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
<tech-list>
<tech>android.nfc.tech.Ndef</tech>
<tech>android.nfc.tech.NdefFormatable</tech>
</tech-list>
</resources>
Contribution
Please feel free to contribute in anyway!
License
This repository is distributed under MIT license