Skip to content

Flutter plugin to emulate an NFC card, work in peer to peer mode.

License

Notifications You must be signed in to change notification settings

ryanhz/nfc_emulator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

27 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

NFC Emulator

A Flutter plugin to emulate the NFC tag. Supported only on Android (Apple is being Apple).

This NFC Emulator plugin was written mainly for the CIDRON reader (the AID is in the example): http://www.civintec.com/info_22.aspx?itemid=35

This kind of reader is using peer-to-peer mode to exchange data, which includes the AES encrypted card UID.

Note: It is impossible for Android to emulate an NFC tag with constant UID in host card emulation mode, please refer to https://stackoverflow.com/questions/46484272/emulate-nfc-card-with-selected-uid-on-android and https://stackoverflow.com/questions/9662979/how-to-fix-uid-in-nfc.

Installing

Add to pubspec.yaml:

dependencies:
  nfc_enumator: <latest version>

Android Setup

Add NFC permissions to Android package's manifest file AndroidManifest.xml:

<uses-permission android:name="android.permission.NFC" />
<uses-feature android:name="android.hardware.nfc" android:required="false" />
<uses-feature android:name="android.hardware.nfc.hce" android:required="false" />
<uses-permission android:name="android.permission.VIBRATE" />

And aid_list.xml to the android/app/src/main/res/xml folder (create if not exist). See example project

File: aid_list.xml ``` ```

Add emulator service with such metadata to AndroidManifest.xml:

<service
	android:name="io.flutter.plugins.nfc_emulator.NfcEmulatorService"
	android:exported="true"
	android:permission="android.permission.BIND_NFC_SERVICE">

	<!-- Intent filter indicating that we support card emulation. -->
	<intent-filter>
		<action android:name="android.nfc.cardemulation.action.HOST_APDU_SERVICE" />
		<category android:name="android.intent.category.DEFAULT" />
	</intent-filter>
	<!--
			Required XML configuration file, listing the AIDs that we are emulating cards
			for. This defines what protocols our card emulation service supports.
	-->
	<meta-data
		android:name="android.nfc.cardemulation.host_apdu_service"
		android:resource="@xml/aid_list" />
</service>

Example of Usage

Check NFC Status:

// Check NFC Status
int nfcStatus = await NfcEmulator.nfcStatus;

Start NFC Emulator

// Start NFC emulator with AID, cardUid, and optional AES key:
await NfcEmulator.startNfcEmulator("666B65630001", "cd22c716", "79e64d05ed6475d3acf405d6a9cd506b");

Stop NFC Emulator

// Stop NFC emulator:
await NfcEmulator.stopNfcEmulator();

See more at: example project

About

Flutter plugin to emulate an NFC card, work in peer to peer mode.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published