Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can my app find out which NFC mode is enabled?

I've found that Android devices support three NFC modes: reader/writer, P2P, and card emulation.

Is it possible for my app to check which mode is currently enabled?

like image 808
hoonj Avatar asked Apr 24 '15 08:04

hoonj


People also ask

How do I check NFC support?

You can check for NFC settings on your Samsung Android device by looking in the settings app > connections > tap NFC and contactless payments. If you see an option for NFC there, your device is enabled to make NFC payments.

How do I know what type of NFC tag I have?

Physical TestingSmall quantities of NFC tags can be tested by manually using an NFC enabled mobile device and an app such as the GoToTags Android App or GoToTags iOS App. For larger quantities of NFC tags, setting up a testing station using the GoToTags Windows App and an NFC reader might be more appropriate.

Is NFC automatically on?

The majority of new Android smartphones have an NFC chip in the phone. Your phone's NFC chip (and Android Beam) needs to be activated before you can use NFC: Go to Settings > More. Tap on the NFC switch to activate it.

Does NFC turn on by default?

Turning NFC On and Off Once you have determined if your device supports NFC, it's important to understand how to turn the feature on and off. Depending on the manufacturer, it's possible your device supports NFC but, by default, came with it switched off in the settings.


1 Answers

No, your app can't really check what mode is currently enabled. The point is that, by default, an Android device will periodically check for all three modes (actually it's a bit more complicated than that: those three modes are themselves split into several parts, each polling for a certain technology). So, while the screen is on, you can expect the Android device to cyclically switch between listening for other readers and polling for different types of tag technologies and peer-to-peer mode devices. This is the case regardless of whether you registered to send a message over peer-to-peer mode, an app is registered for HCE, or your app registered for NFC discovery intents. Even if you disable Android Beam in settings, the device will remain to poll for peer-to-peer mode.

Only if you explicitly disable card emulation and P2P using the reader mode API (available on Android 4.4+), your app can control that only reader/writer mode is active (and it can even control which tag technologies should be polled for).

So your app can know what modes it enabled itself and can do some guessing, e.g.

  • if the screen is on and reader/writer mode was not explicitly forced using the reader mode API, all three modes are likely to be active.
  • if the screen is off, only card emulation mode may be active (though this is device dependent and HCE is usually not available).
like image 190
Michael Roland Avatar answered Sep 20 '22 06:09

Michael Roland