Code Monkey home page Code Monkey logo

external-nfc-api's Introduction

External NFC Service (native style) for Android

Library for interaction with ACS NFC readers over USB; external NFC support Android devices.

Features:

  • External NFC reader management and interaction
  • Parallell use of external and/or internal NFC (i.e. in the same activity, both enabled at the same time)
  • Support for both tags and Android devices (Host Card Emulation), simultaneously
  • Use of forked android.nfc classes (Ndef, MifareUltralight, IsoDep, etc) for Android 10+ support.

As this project very much simplifies implementation for use-cases requiring external NFC readers, it saves a lot of development time (2-8 weeks depending on use-case and previous knowledge).

Alternative

Most of the code within this repository has been refined into Entur's android-nfc-lib. This does not include

  • NDEF handling
  • Bluetooth reader

License

Apache 2.0

Usage

This repository contains source code for

There is also a Host Card Emulation client app for use with the Basic client app as well as Android-to-Android communication.

External NFC reader API

The API defines

  • broadcast actions
    • service start / stop and status
    • reader open / close and status
    • tag connect / disconnect
  • extras objects for interaction with readers
    • disable beeps
    • display text
    • configure NFC tech types (PICC)
    • enable/disable LEDs
    • run custom commands
    • and more..
  • abstract activities for interaction with built-in and external NFC (simultaneously)
  • these currently depend on the NDEF Tools for Android project.
  • Programmatically start and stop the service (see methods startService() and stopService() in the NfcExternalDetectorActivity class in for an example).

Supported readers

Currently the ACS readers

are supported and must be connected to your Android device via an On-The-Go (OTG) USB cable.

Additional ACR readers might work depending on their command set, however custom reader commands will (like LED, beep etc) will not be available.

Supported tag technology

The following tags are supported by the service

  • Mifare Ultralight familiy
    • Mifare Ultralight
    • NTAG 21x with FAST READ
  • Mifare Classic and friends
    • Not recommended due to security and compatibility issues
  • Desfire EV1 tags
  • Host Card Emulation - interaction with Android devices.

The readers can for the most part can be enabled for all tag types at the same time, including Host Card Emulation.

Please note:

  • Some readers only support a subset of the above tags
  • For ACR 122U the Mifare Classic does not work well.
  • No built-in NDEF support for Desfire EV1 cards

Configuration options

  • assume all NTAG21x Mifare Ultralight targets. This improves read speed, particullary for the tags which have legacy equivalents, like NTAG 210 and 213
  • read only tag UIDs, ignore other tag data. This improves read speed.
  • read NDEF data automatically
  • read UID for Desfire EV1 targets automatically

Reader connection

Note that not all Android devices actually have an USB hub, in which case no USB devices work.

Does the ACR reader not light up when connected to your device, even after the service asks for USB permissions? The ACR reader shuts down if there is not enough battery, so try charging your battery more, or connect external power.

If you are using external power, be aware that the connection order (device, reader, power) might be important. Known symptom:

  • Seeing an USB permissions window that disappears rather quickly.

Tag detection

There is quite a few types of tags out there, and if your tag type is not recognized, please let me know. If the tag does not register at all, make sure that auto polling is configured, and that the right protocols are enabled. Use the below utility apps for tweaking your reader settings.

Reader setting utility apps

You might be interested in

for configuration of your reader. Approximately the same configuration options are available using this API.

See also

This project contains adapted code from

  • NFC Tools for Java
  • SMARTRAC SDK for Android NFC NTAG

History

  • 2.1.0: Improve bluetooth handling, various bug fixes and a few improvements.
  • 2.0.0: Moved to wrapped android.nfc NFC android classes + various refactorings.
  • 1.0.0: Library using native NFC android classes

external-nfc-api's People

Contributors

skjolber avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

external-nfc-api's Issues

NFC ACR 122U Reader Not working

Hello skjolber,
I am using this sample. I connect NFC ACR 122U Reader by USB with my samsung galaxy tab A6 and run externalNFCClient application. Then app not connected with reader.
When i have installed External NFC Reader Service app(https://play.google.com/store/apps/details?id=com.skjolberg.nfc.external).Click on Start service now button then USb device connecttion window appear and reader connected.After connection i have again test sample then it's worked fine.

So please provide any sample to connect NFC ACR 122U Reader by USB.

Setting up android client with Bluetooth

Hi, I have been trying to compile the libraries so I can get the phone connected to the acr1255U-J1 with no luck. Any chance of a sample code on that?

Magical thanks in advance.

Using an ACR reader to emulate an ISO 7816 card app

Hi,

With the current library, is it possible to use the ACR reader (for example the ACR122U) in card emulation mode to emulate an ISO 7816 compatible smart card application? If so, is there a code example for this? The only HCE code I could see was a test Android HCE app but I may be missing something.

Thanks,

Martin Patefield-Smith

Unable to read tag UID

Hi skjolber and thank for this great collection of nfc tools.
I am using the server-example application and try to get the tags UID.
With Mifare Desfire tags there is no problem and it works perfect. But at MIFARE Classic 1k tags the logs always shows the following logs:
2020-09-07 08:43:32.053 3791-3803/com.github.skjolber.nfc.external I/com.github.skjolber.nfc.service.BluetoothBackgroundService: onCardStatusChange sta: Present. 2020-09-07 08:43:32.057 3791-3803/com.github.skjolber.nfc.external D/com.github.skjolber.nfc.service.BluetoothBackgroundService: Power on card.. 2020-09-07 08:43:32.138 3791-3803/com.github.skjolber.nfc.external D/com.github.skjolber.nfc.service.BluetoothBackgroundService: onAtrAvailable: 3b8f8001804f0ca000000306030001000000006a 2020-09-07 08:43:32.139 3791-3803/com.github.skjolber.nfc.external D/com.github.skjolber.nfc.service.BluetoothBackgroundService: Got tag type MIFARE_CLASSIC_1K 2020-09-07 08:43:32.141 3791-7026/com.github.skjolber.nfc.external D/com.github.skjolber.nfc.service.BluetoothBackgroundService: Regular mode 2020-09-07 08:43:32.615 3791-7026/com.github.skjolber.nfc.external W/com.github.skjolber.nfc.service.AbstractService: Unable to read tag UID

Am I doing something wrong or does the application not support MIFARE Classic 1k?

device not detected

Hi,
i've tried both the client and the kiosk apps but the acr122 is not detected, the usb dialog doesn't come out.
I've also tried the acr122 app on play store and it works like a charm.

Do you have any feedback on this?

Thanks

Android Things

I have an NFC Reader/Writer that is USB (ARC122u). I am trying to test this out to work with my Pi. I am getting Native NFC is not available. How can I get this working?

Thanks

Feature Request: Enable WebNFC in Android Chrome with external NFC Reader

Hi,

We would have a use case for using external NFC Readers with a Chrome Website. The External NFC Service on Android can read and provide the data to apps but Chrome seems to ignore everything that is not an internal NFC reader.

Do you see any possibility of this ever working? I'd guess it's pretty much impossible without either support by Google or root.

PN532 Support

Hi,

Can you please add support for the PN532 module from Elechouse?
Full documentation is available here: PN532_Manual_V3.pdf
You may also check GNFC and PN532-HSU.py for reference.

The HSU (High-Speed UART as they call it) can be used to communicate with External NFC using a UART to Serial breakboard, such as FTDI or CH340G.

PN532

technology is not supported by the NFC Adapter

When trying to connect to an UltralightC i get the following message:

Connecting to this technology is not supported by the NFC adapter.

I've tried it with both the ARC122U-A9 Reader and the ARC1252U-A1

I'm running android 5.1.1 on an ODROID C2

Tag tag = (Tag)intent.getParcelableExtra(NfcAdapter.EXTRA_TAG);
NfcA nfca = NfcA.get(tag);
try {
    nfca.close();
    nfca.connect();
} catch (Exception e) {
 e.printStackTrace();
}

Quick question about Ultralight EV1 and Desfire EV1

Hi

I came across your Mifare Desfire EV1 tool on App store, very cool. I got 2 very quick questions about the Mifare SDK not sure if you can help me with that.

1.)Does the Ultralight EV1 password protection provides the same level of protection as the Desfire EV1??
(Because on my use case i dont need that much memory saved, just about 200-300bytes of data stored, but i need additional security) I have heard that with TagInfo reader, the NTAG 21x family encrypted data can still be read.

2.) Does the Mifare Android LITE SDK allows setting/resetting password and write into 3DES encryption area?(Set the password, then set which area is protected like NTAG 2x?(I am quite new to this, still trying to figure out how it works). Or would i have to use the Advanced SDK??
Using similar functions to NTAG 21x to set password? like
your_object.programPWDPack(byte[] pwd, byte[] pack)

Ionic Usage

Hello,

I bought "External NFC Reader Service" application and I am trying to make it work with a Ionic app using @ionic-native/nfc (with phonegap-nfc plugin behind).

I have no knowledge in Android development and I don't know where to start, could you please point me in the right direction ?

Thank you :-)

HCE app can't connect to Basic app

I have a acr1252u reader.
I want to use the reader for hce reader. So I tested with externalNFCHostCardEmulationClient and externalNFCClient. But no log was output for externalNFCHostCardEmulationClient.

When I check log in android studio, I saw "No reader supplied" log. Does this log relate to the problem?
What I have to do?

Refactor server / client approach for Android 10

Background services seem to be handled in a stricter way in the newer (10?) Android versions, so this server / client approach is not really working very well (the server service is stopped). Rewrite so that the server example is included as a configuration activity in the other examples.

Can't Read NDEF Message AC122U Card Mifare Classic

Bug i found Can't Read NDEF Message AC122U Card Mifare Classic
Peripheral i use for Dev :

  • HTC One M9 - Android 9
  • ACS ACR 122u
  • Card Mifare Classic

from this repo i was upgrade lib use ver 1.1.5 download from acs, compileSdkVersion and targetSdkVersion change to 26
I run externalNFCService use adb wireless to get logcat
Lastly i got error like this below picture, NDEF Message from my Card Mifare Classic was Encoded by gototag.com can't read. in log UUID the Card was read perfect. Less NDEF Message

nfc---

How to get tagId in server example?

https://github.com/skjolber/external-nfc-api/blob/master/examples/server/src/main/java/com/github/skjolber/nfc/external/MainActivity.java

private final BroadcastReceiver tagReceiver = new BroadcastReceiver() {

	public void onReceive(Context context, Intent intent) {

		String action = intent.getAction();

		Log.d(TAG, "Custom broacast receiver");

		if(intent.hasExtra(NfcAdapter.EXTRA_ID)) { // Not Working...
			byte[] id = intent.getByteArrayExtra(NfcAdapter.EXTRA_ID);
			Log.d(TAG, "Tag id " + toHexString(id));
		}

		setTagPresent(!NfcTag.ACTION_TAG_LEFT_FIELD.equals(action));
	}
};

https://github.com/skjolber/external-nfc-api/blob/master/core/src/main/java/com/github/skjolber/nfc/service/BackgroundUsbService.java

private void handleTagInitRegularMode(int slotNumber, byte[] atr, TagType tagType) throws ReaderException {
	AcsTag acsTag = new AcsTag(tagType, atr, reader, slotNumber);
	IsoDepWrapper wrapper = new ACSIsoDepWrapper(reader, slotNumber);
	Log.d(TAG, "Handle tag in regular mode " + tagType); // tagType is UNKNOWN
	...
}

What I missed?

Android-x86 integration

Hello, Thomas!

Have you tried to integrate External NFC Reader Service into any Android-x86 build to get NFC working "out-of-box"? I have ACR1281U-C1 reader and I'd like to use it under VirtualBox guest w/ all the capabilities including HCE. Do you have some guide or instructions for how anyone could build Android-x86 from the sources along with your service? Or maybe you're planning to release one?

New versions of android have changes for broadcast system, code needs to be updated.

For myself, for now, I was able to fix broadcast issue by adding this in external activity class:

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
			registerReceiver(readerReceiver, filter, Context.RECEIVER_NOT_EXPORTED);
		} else {
			registerReceiver(readerReceiver, filter);
		}

--Also I wanted to ask if this project is still active and if I can create pull request to also add other fixes to Issues I noticed--

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.