I have an app which connects to smartcards, but when the display turns off, the app disconnects from the smartcard. Is it possible to turn the screen off but keep NFC active so that the app can send data to the smartcard and receive them?
No that's (usually) not possible. On all (most?) Android devices, the NFC stack disables the reader functionality (and puts the NFC chipset into a low-power mode) when the screen turns off. The reason for this is pretty simple: You certainly do not want the NFC reader to drain your battery when you are not using your device (and a mobile device is typically not used when its screen is off). Hence, the only option is to keep the screen on while reading the tag. You can easily do this by adding the FLAG_KEEP_SCREEN_ON to your foreground activity.
This is because the application goes into background. You can try using a service in android to access the card when the application is in background. Be aware that this will consume more battery power.
You can refer this for better understanding
Related
I 'm developping a continue scan android app, because I have to collect some important info from another device , I have to scan ble device,and never stop, otherwise, I may miss some important info. Is there any way for a android app to continue Bluetooth Low Energy scan,never stop ,scan for a year if the important device don't appear. During the year, my android phone always keep sufficient electricity,but sometimes I will press home button , sometimes I will make Screen Off (not power off ,just make screen off).
Modern Android has implemented various battery saving measures which will prevent you from continuous data collection.
Doze mode is implemented by the Android framework. See: Scanning for Bluetooth LE devices when the phone is in doze mode, don't work. CallBack method doesn't called when doze mode
Additionally various device manufacturers have implemented their own battery savings systems which will kill your app even when you are following Android framework rules. See: https://dontkillmyapp.com/ for details.
Can a passive NFC tag harvest power from a smartphone when its screen is locked? In other words will there be a magnetic field when the screen of the phone is locked ? I understand that you cannot read an NFC tag or write on it when the screen is locked but the question here is about the power (i.e. the magnetic field)
thanks
It depends on the OS and power management of the phone device you are referring to.
One of the main reason why Read operations are generally not enabled when the screen is locked is that the operation to perform on a tag in proximity is generally user driven. In the screen lock state user cannot provide such input. Also, one has to be sure which app of phone is processing the tag.
Talking about NCI 1.0 there is no command that directs the firmware to behave differently based on the Screen state. So, a discovery cycle started with screen on will continue to remain on in the screen locked state. But OEM's may have implemented proprietary commands/configs to achieve better control.
NCI 2.0 supports disabling Poll/Listen in certain states of Screen using a Set Config.
I'm currently write Android HCE application. And I want to use my HCE application when the device is turned off. I found a way to "Access HCE when Screen off", but no information of power off status.
Is there any way to use HCE application when phone is turned off?
No you can't access because of security reason
One correction also its not accessible if screen is off as mentioned in provided link.
Current Android implementations turn the NFC controller and the application processor off completely when the screen of the device is turned off. HCE services will therefore not work when the screen is off.
It may work on some devices only if vendor implements the OS customized.
I want to be able to detect a simple NFC tag, and turn the phone on silence and then turn the silence off again, when the tag is removed. I have this all working when the phone is unlocked, but I need the app to work when the phone is locked. How would I go about getting this to work?
It's not possible to achieve this via your application alone. The core NFC service specifically forbids it. Users can either replace their NFC apk with one that does allow it, or install an Xposed module, but neither of those are something I would want to be instructing people to do, for security reasons.
Another downside would be the excessive battery usage due to the phone having to poll for NFC events.
I would like to create an app that listens for NFC tag scans for several hours. A new NFC intent will normally happen every 2-3 minutes but sometimes 10-15 minutes apart.
The phone may be sitting in a users pocket while running so there is a possibility of accidental touch to the interface.
What options do I have to stop the phone going to sleep in between each NFC intent so that the user does not need to continually wake up the phone to scan a new NFC tag?
Rooting users phones to always enable NFC is not an option in this scenario.
The only thing I can think of is to create a blank screen with a custom unlock code/swipe so there is no accidental pushes... but this would use a lot of battery?
Some phones will keep scanning for NFC even when the screen is locked, some won't.
There are security reasons (some tag payload can be forged to attack the NFC stack), and obvious battery saving reasons. The current GSMA recommendation in this area that NFC scanning be turned off as long as the screen is off. The impact of the battery will depend on the chip embedded in your phone, but the impact should be noticeable. Depending on your use case doing card emulation by the phone or UICC might be more efficient.