Giter VIP home page Giter VIP logo

nfc_emulator's Introduction

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

nfc_emulator's People

Contributors

ryanhz avatar zigapovhe avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.