I have an app that reads various types of NFC tag. For years it's worked fine, but with newer Android devices a java.io.IOException
is thrown consistently when scanning a particular type of tag. The tag in question has support for both Mifare Classic and ISO-DEP, but we're connecting using the IsoDep
technology specifically.
Neither the NFC TagInfo or NFC TagInfo by NXP apps are able to read the tag without error either.
Devices that work:
- Moto X Play (Android 6.0.1)
- Moto G Play (Android 6.0.1)
- Samsung Galaxy S7 (Android 7.0)
- Samsung Galaxy S8 - UK model (Android 7.0)
- Pixel 2 (Android 8.1)
Devices that fail:
- Moto G5S (Android 7.1.1)
- Moto Z2 Play (Android 7.1.1)
- Moto E4 Plus (Android 7.1.1)
- Huawei Honor 8 (Android 7.0)
- LG K8 (Android 7.0)
- LG K10 (Android 7.0)
- Samsung Galaxy S8 - US model (Android 7.0)
The code needed to repro the issue is dead simple.
The NFC intent is received through foreground dispatch, and the following then runs in its own thread (with no other threads or NFC-related processing in between):
IsoDep isoDep = IsoDep.get(tag);
try {
isoDep.connect();
}
catch (IOException e) {
Log.e("NFC", ":(");
}
When the IOException
is thrown by the connect()
method within android.nfc.tech.BasicTagTechnology
, the errorCode
is -5 (ERROR_CONNECT).
Interestingly, for the devices that work, the tech list exposed by the Tag
is as follows: android.nfc.tech.IsoDep, android.nfc.tech.NfcA
For devices that don't work the tech list is much longer, and contains duplicates: android.nfc.tech.IsoDep, android.nfc.tech.NfcA, android.nfc.tech.NfcA, android.nfc.tech.MifareClassic, android.nfc.tech.NdefFormattable
Finally, for devices that don't work, the following entry crops up in logcat: E/NxpNfcJni: Mifare Classic detected
Is it possible that with the extended NFC support offered by the more modern Android devices there is some confusion within the NFC system service about what TagTechnology to connect to?