Launching NFC when screen is Locked in Android

37,256

Solution 1

This is not supported. I don't think even Google Wallet works this way, are you sure about this? It is actually a security feature -- you don't want someone who stole your phone to be able to make payments with it without being able to unlock it.

Solution 2

According to Google, Android-powered devices must be unlocked in order to scan an NFC tag [1]. Also the Google Wallet concerns privacy and security, and works only in unlocked state [2].

[1] http://developer.android.com/guide/topics/connectivity/nfc/nfc.html

[2] http://www.google.com/wallet/faq.html

Solution 3

I was looking to implement the same feature on one of my applications. After some search i discovered these links:

http://www.xda-developers.com/android/use-nfc-with-screen-off-or-in-lock-screen-on-galaxy-nexus/

Also note that the new Moto X was a feature called "Skip" that allow the same behaviour. You can see a demonstration on this video:

https://www.youtube.com/watch?v=-JUgspIGxcE

Hope it can help

Solution 4

Agreed with Nikolay Elenkov, As you are not able to get hold on Power button as discuss here same way you can't unlock the phone to launch your application while launching your application.

Solution 5

Probably it could work if you use:

getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED);

http://developer.android.com/reference/android/view/WindowManager.LayoutParams.html#FLAG_SHOW_WHEN_LOCKED

Share:
37,256
Venky
Author by

Venky

Android Application Developer

Updated on July 05, 2022

Comments

  • Venky
    Venky almost 2 years

    I want to launch My Application when we taps on NFC tag even Phone is Locked same as did in Google Wallet Application.

    I tried in following ways :

    1) Tap NFC tag to launch my application after pressing Power button - Error :

    05-23 22:00:22.949: D/NfcService(32443): EnableDisableDiscoveryTask: enable = false
    
    05-23 22:00:22.964: D/NfcService(32443): NFC-C polling OFF
    
    05-23 22:00:22.996: D/PhoneStatusBar(273): disable: < EXPAND icons alerts TICKER 
    system_info BACK* HOME* RECENT CLOCK* >
    
    05-23 22:00:23.988: D/NfcService(32443): NFC-EE routing OFF
    [10:33:22 AM IST] 
    

    2)Tap NFC tag after pressing Power button and now i am able to see Lock/Unlock screen - Error :

    05-23 22:03:59.714: D/NfcService(32443): EnableDisableDiscoveryTask: enable = true
    
    05-23 22:03:59.730: D/NfcService(32443): NFC-EE routing OFF
    
    05-23 22:04:03.238: D/NfcService(32443): NFC-C polling ON
    

    If i unlock the screen and Taps on NFC tag everything works fine

    How to handle power button and lock/unlock screen in order to Launch my application when phone is Locked?

  • Venky
    Venky almost 12 years
    It makes sense. I will confirm you regarding Google Wallet.. Thanks for your useful answer
  • Venky
    Venky almost 12 years
    I am sure that Google Wallet works in same way , it unlocks the phone and launch NFC tag if it is locked mode
  • Venky
    Venky almost 12 years
    But Google Wallet does, launching NFC in locked state
  • Mohammed Azharuddin Shaikh
    Mohammed Azharuddin Shaikh almost 12 years
    hmm interesting, ok can you just go through the comments in above link's MrGomez answer?.
  • Nikolay Elenkov
    Nikolay Elenkov almost 12 years
    Does you phone have lock pattern/PIN? If it doesn't, it might be possible, but it's probably using a system only API. What does the logcat look like when you test with Wallet?
  • Venky
    Venky almost 12 years
    I will edit my post with Wallet Logcat , BTW you have any idea about enabling NFC polling?
  • NFC guy
    NFC guy almost 12 years
    Card emulation (what Google Wallet does) and tag reading/writing are 2 different features of the NFC chip. On a phone with Google Wallet, the Secure Element is enabled when the lock screen is displayed (in the logcat you will see NFC-EE ON). However, NFC polling for tags is still turned off. It will only be turned on when you unlock the phone (logcat: NFC-C ON). Both are turned off when the screen is turned off.
  • Venky
    Venky almost 12 years
    No,i am sure that Google Wallet scan NFC tags in unlock mode
  • Nik NexAndrX
    Nik NexAndrX almost 12 years
    You mean in lock mode ? For security reasons the mobile must be unlocked. Read the FAQ i've posted above. Also in XDA you can find mods which offer scanning nfc tags in locked mode..
  • Venky
    Venky almost 12 years
    @NFCguy Now can you please explain what should i do in order to make my App works same as Google Wallet?
  • NFC guy
    NFC guy almost 12 years
    @Venky I don't know exactly. I think the Google Wallet app reacts to a broadcast message generated by the NFC service when a card reader tries to access the Google Wallet applet on the Secure Element. You could try to find out what kind of broadcast message this is and add a broadcast receiver for it to your own app. Still, you probably need to root your phone to bypass the lock screen and you still cannot react to an NFC tag. And if you are going to root your phone, you may just as well turn on NFC reader/writer mode when the screen is turned on, I suppose.
  • NFC guy
    NFC guy almost 12 years
    @NikNexAndrX No, I agree with Venky. I tested it myself: the Google Wallet PIN screen will pop up when you hold your locked phone, with screen turned on, to a payment terminal.
  • Nik NexAndrX
    Nik NexAndrX almost 12 years
    Strange. In which mobile and version of Android ?
  • ondermerol
    ondermerol over 8 years
    Does Google Wallet PIN screen pop up when you hold your locked phone really?
  • Martin
    Martin over 4 years
    Google Pay works in locked but screen-on mode for up to 25 EUR. That is, on my OnePlus 3 with Android 9 (OxygenOS 9.0.6).