nfc_emulator 2.0.0-nullsafety.0 copy "nfc_emulator: ^2.0.0-nullsafety.0" to clipboard
nfc_emulator: ^2.0.0-nullsafety.0 copied to clipboard

PlatformAndroid
outdated

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

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

25
likes
130
pub points
75%
popularity

Publisher

verified publishermetaware.dev

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

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (LICENSE)

Dependencies

flutter

More

Packages that depend on nfc_emulator