在 Android 中锁定屏幕时启动 NFC

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10733723/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 04:48:08  来源:igfitidea点击:

Launching NFC when screen is Locked in Android

androidnfcpower-management

提问by Venky

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

我想在我们点击 NFC 标签时启动我的应用程序,即使手机谷歌钱包应用程序中的一样被锁定

I tried in following ways :

我尝试了以下方法:

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

1) 按下电源按钮后,点击 NFC 标签以启动我的应用程序 -错误

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:

2)按下电源按钮后点击 NFC 标签,现在我可以看到锁定/解锁屏幕 -错误

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

如果我解锁屏幕并点击 NFC 标签,一切正常

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

如何处理电源按钮和锁定/解锁屏幕以在手机锁定时启动我的应用程序?

采纳答案by Nikolay Elenkov

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.

这不受支持。我认为即使是 Google 电子钱包也不能这样工作,你确定吗?它实际上是一项安全功能——您不希望偷了您手机的人在无法解锁的情况下使用它付款。

回答by Nik NexAndrX

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].

根据谷歌的说法,Android 设备必须解锁才能扫描 NFC 标签 [1]。此外,谷歌钱包关注隐私和安全,并且只能在解锁状态下工作 [2]。

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

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

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

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

回答by D-C0d3r

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/

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:

另请注意,新的 Moto X 是一项名为“跳过”的功能,它允许相同的行为。您可以在此视频中看到演示:

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

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

Hope it can help

希望它可以帮助

回答by Mohammed Azharuddin Shaikh

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

同意Nikolay Elenkov 的意见,因为您无法像此处讨论的那样按住电源按钮,因此您无法在启动应用程序时解锁手机以启动应用程序。

回答by Hollerweger

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

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