Exclude non-NXP Android phones with NFC (like the

2019-01-24 19:51发布

问题:

I've built an app that reads out certain data from the student ID cards our school uses. Right now it only reads user data but in the future the plan is to add support to read the remaining credit.

The problem is that the cards we use are Mifare Classic. Nexus 4 and Nexus 10 (and possibly more devices) don't support these cards since they have a Broadcom NFC controller. If I'm right the app shouldn't crash or give issues on those devices, but it just doesn't do anything.

Is there a way to somehow exclude these devices without NXP controller? (Basically like uses-feature required for the MifareClassic class.) I can exclude the Nexus 4 and 10 through the Play Store but that's hardly a good solution - even more because other devices might start using Broadcom controllers and they'd all have to be excluded manually.

Thanks! - Ambroos

回答1:

You can check in your app for MIFARE Classic support as follows:

boolean hasMifare(Context ctx) {
 return ctx.getPackageManager().hasSystemFeature("com.nxp.mifare");
}

There is no way to check for this before installing the app. But after installation, you can warn the user that the functionality of your app will be limited, because of the lack of MIFARE Classic support.



回答2:

Apparently, the UID can still be read by those phones.

Can NFC Mifare Classic Tags be used at all with the Nexus 4 and 10?

YES! And no. While Mifare Classic Chips can not be written to or fully read by the Nexus 4 or 10, their UID (a unique identification code) can be detected and read. So Mifare Classic Chips can be used with the Nexus 4 or 10 along with an app such as AutomateIt which simply uses a tag's UID to trigger events/settings saved on the device. (ReTag & NFC Task Launcher also can just use a tag's UID but also have the ability to write to writable tags.) The down side to this is that because the tag can not be written to, if you have more than one of these types of NFC apps on your phone, tapping the tag will bring up a box to ask you what app you want to use. But if you only use one NFC app for all your Tag Events/Settings/etc., then this is not a problem and would allow you to make use of Mifare Classic tags for this purpose.

Read more at http://andytags.com/nfc-tags-nexus-4--10-compatibility.html#47A4kbkkGceGqe3L.99

I'd suggest you try to use the same principles that are used in progressive web enhancements programming, and use guard conditions wrapped inside of try/catch blocks to guard against each small function/assumption instead of filtering based on a name/brand only.

This way, if some manufacturer creates faulty tags, or if the user tries to scan two tags at the same time by mistake, or if a user removes the phone too quickly before a scan is complete, or whatever else happens in the future, your application will be able to cope more readily with those types of error conditions.