Skip to content
This repository has been archived by the owner on Jun 23, 2024. It is now read-only.

Commit

Permalink
Support host card emulation (#1)
Browse files Browse the repository at this point in the history
* Experimental reader mode API on Android

Using a lot of code from
https://code.tutsplus.com/tutorials/reading-nfc-tags-with-android--mobile-17278

Current caveats and to-dos:
Tags content type must be text/plain. This is a hardcoded value.

* Possible fixes

* Finalize host card emulation support

* Revert readerMode in example

Formatting is crazy
  • Loading branch information
semlette authored Jul 6, 2019
1 parent 4416565 commit 41f3a72
Show file tree
Hide file tree
Showing 10 changed files with 282 additions and 103 deletions.
7 changes: 7 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

91 changes: 54 additions & 37 deletions .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,26 @@ If your app **requires** NFC, you can add the following to only allow it to be d

If you're new to NFC you may come to expect a lot of `readNFC()` calls, but instead you see `readNDEF()` and `NDEFMessage`. NDEF is just a formatting standard the tags can be encoded in. There are other encodings than NDEF, but NDEF is the most common one. Currently NFC in Flutter only supports NDEF formatted tags.

## Host Card Emulation

NFC in Flutter supports reading from emulated host cards, however only on Android as Apple doesn't allow it on iOS.

To read from emulated host cards, you need to do a few things.

- Call `readNDEF()` with the `readerMode` argument set to an instance of `NFCDispatchReaderMode`.
- Insert the following `<intent-filter />` in your `AndroidManifest.xml` activity:

```xml
<intent-filter>
<action android:name="android.nfc.action.NDEF_DISCOVERED" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
```

### ⚠️ Multiple reader modes

If you start a `readNDEF()` stream a `NFCDispatchReaderMode` while another stream is active with the `NFCNormalReaderMode`, it will throw a `NFCMultipleReaderModesException`.

## Platform differences

When you call `readNDEF()` on iOS, Core NFC (the iOS framework that allows NFC reading) opens a little window. On Android it just starts listening for NFC tag reads in the background.
Expand Down
Loading

0 comments on commit 41f3a72

Please sign in to comment.