The nfc card-emulation on android
Inspired by android-CardEmulation
ππ₯Only supported Android !π₯π
- Android (API 19+)
- Android SDK 27
- Android Build Tools v27.0.2
$ npm install react-native-nfc-hce --save
$ react-native link react-native-nfc-hce
#### Android
1. Open up android/app/src/main/java/[...]/MainActivity.java
- Add import studio.bb.rnlib.RNHcePackage; to the imports at the top of the file
- Add new RNHcePackage() to the list returned by the getPackages() method
2. Append the following lines to android/settings.gradle:
```
include ':react-native-hce'
project(':react-native-hce').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-hce/android')
android/app/build.gradle
3. Insert the following lines inside the dependencies block in :`
`
compile project(':react-native-hce')
1. Open up android/app/src/main/AndroidManifest.xml
- Add `
- Add
`
android:exported="true"
android:permission="android.permission.BIND_NFC_SERVICE">
android:resource="@xml/aid_list" />
2. Create aid_list.xml in android/app/src/main/res/xml/
- Add code in aid_list.xml
`xml`
android:requireDeviceUnlock="false">
android:description="@string/card_title">
The aid need to customize
- Edit AID in react-native-nfc-hce/android/src/main/java/studio/bb/rnlib/CardService.java
`JAVA
public class CardService extends HostApduService {
private static final String TAG = "CardService";
private static final String AID = "F201808175";
`
`javascript
import HCE from "react-native-hce";
componentDidMount = () => {
const { support, enabled } = HCE.supportNFC();
HCE.listenNFCStatus(enabled => {
console.log("NFC enabled: ", enabled);
});
};
_onChangeText = text => {
if (text.length > 0) {
HCE.setCardContent(text);
}
};
``
Get NFC supported and enabled
Listen NFC enabled status
Write CardEmulation content