Android 如何在安卓手机上模拟 nfc 标签

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10831994/
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 05:08:57  来源:igfitidea点击:

How to emulate a nfc-tag on an android phone

androidnfc

提问by sinned

I have an android phone (nexus s, sdk v15) which shall send a string to a development board running in nfc-reader/writer-mode by using tag-emulation. I know this is not officially supported by android, so I could do it natively by accessing the driver directly(?).

我有一部 android 手机(nexus s,sdk v15),它将使用标签仿真将字符串发送到在 nfc-reader/writer-mode 下运行的开发板。我知道这不是 android 官方支持的,所以我可以通过直接访问驱动程序(?)来本地完成它。

Is there any example out there where anyone has done this before or an app which does this (and preferably is open source?)

有没有任何人以前做过这个的例子,或者有一个应用程序可以做到这一点(最好是开源的?)

I found some stuff on google where it is generally advised not to do this, or where people talk about how it would be possible or how they've (very generally) done it, but I couldn't find any code or precise advice.

我在 google 上发现了一些通常建议不要这样做的东西,或者人们谈论它是如何可能的或者他们是如何(非常普遍地)完成它的,但我找不到任何代码或精确的建议。

I don't want to access the secure element or do any smartcard stuff that needs to be approved by the vendor/provider. I just want to transfer the string. I also know this could be done by the android api methods via p2p, but this doesn't work well with the board, so I give this approach a try.

我不想访问安全元件或执行任何需要供应商/提供商批准的智能卡操作。我只想传输字符串。我也知道这可以通过 android api 方法通过 p2p 来完成,但是这不适用于董事会,所以我尝试了这种方法。

回答by Peanut

For a device running stock KitKat 4.4

对于运行库存 KitKat 4.4 的设备

With Android KitKat 4.4the ability to have the phone act as an NFC cardis built into the operating systemso you no longer have to rely on Cyanogenmod or a custom ROM. It won't let the phone act as a Mifare Classic tag per se but I've had great results in getting my phone to communicate with an ACR122 readerso I'd definitely recommend this option if you can get 4.4 on your device.

随着Android的奇巧4.4,可让手机充当NFC的功能内置在操作系统中,因此您不必再依靠的CyanogenMod或自定义ROM。它不会让手机本身作为 Mifare Classic 标签,但我在让我的手机与ACR122 阅读器通信方面取得了很好的效果,所以如果你的设备上能获得 4.4,我肯定会推荐这个选项。

If you're wanting to run below 4.4 and are willing to use Cyanogenmod

如果你想运行低于 4.4 并且愿意使用 Cyanogenmod

It is possible to load applications onto your deviceand have them communicate with a reader via NFC quite easily however you must be running Cyanogenmod, this feature is present from CM 9.1.

可以将应用程序加载到您的设备上并让它们通过 NFC 很容易地与阅读器通信,但是您必须运行Cyanogenmod,此功能从 CM 9.1 开始

Wanting to run on Gingerbread(the old answer)

想要在 Gingerbread 上跑步(旧答案)

Yes it is possible and there's been a patch put out there for 2.3.4 to enable it, I'll post a few links for you to have a read of.

是的,这是可能的,并且已经为 2.3.4 发布了一个补丁来启用它,我将发布一些链接供您阅读。

They do require flashing a 2.3.4 Gingerbread ROM to your device along with some other patches to enable the card emulation features so if you're not willing to do that then they won't be of much use but as far as I'm aware it's the only way to get it working. I haven't actually tested this myself but user comments suggest it works.

它们确实需要将 2.3.4 Gingerbread ROM 与其他一些补丁一起刷入您的设备以启用卡模拟功能,因此如果您不愿意这样做,那么它们将没有多大用处,但就我而言意识到这是让它工作的唯一方法。我自己还没有实际测试过,但用户评论表明它有效。

Here is a link to a blog describing the whole process: http://techshek4u.blogspot.co.uk/2012/01/applying-card-emulation-patch-to_03.html

这是描述整个过程的博客的链接:http: //techshek4u.blogspot.co.uk/2012/01/applying-card-emulation-patch-to_03.html

Here is a link to the original forum post with the patch for 2.3.4 to enable it:
http://forum.xda-developers.com/showthread.php?t=1281946

这是原始论坛帖子的链接,其中包含 2.3.4 的补丁以启用它:http:
//forum.xda-developers.com/showthread.php?t=1281946

And a link to the original discussion where various developers are trying to get it working, depending on your technical knowledge of Android and NFC this could be more or less interesting: https://groups.google.com/forum/#!msg/android-developers/1fw1qfFqpGc/6dlzvTqExN4J

以及各种开发人员试图让它工作的原始讨论的链接,这取决于您对 Android 和 NFC 的技术知识,这可能或多或少有趣:https: //groups.google.com/forum/#!msg/安卓开发者/1fw1qfFqpGc/6dlzvTqExN4J

Caution: According to NFCGuy from his answer "Don't bother with downgrading your phone to GB if it is running ICS. You cannot downgrade the NFC firmware to be compatible again with GB, so NFC will simply not work if you flash your device with GB."

注意:根据 NFCGuy 的回答,“如果运行 ICS,请不要将手机降级到 GB。您无法将 NFC 固件降级以再次与 GB 兼容,因此如果您使用闪存闪存设备,NFC 将无法正常工作GB。”

回答by NFC guy

If you root your device, it is possible to create an app that turns on the card emulation mode. It is not too difficult, see e.g. https://stackoverflow.com/a/10506299/1202968.

如果您对设备进行 root,则可以创建一个打开卡模拟模式的应用程序。这并不太难,例如参见https://stackoverflow.com/a/10506299/1202968

However, card emulation is completely handled by the Secure Element. Your app has no access to the data that is being transferred. The only way to get control over that would be to create and install a Java Card applet on the Secure Element. However, to be able to do that you need acces to secret authentication keys that are only known to Google.

但是,卡模拟完全由安全元件处理。您的应用无权访问正在传输的数据。获得控制权的唯一方法是在安全元件上创建和安装 Java Card 小程序。但是,要做到这一点,您需要访问只有 Google 知道的秘密身份验证密钥。

PS: Don't bother with downgrading your phone to GB if it is running ICS. You cannot downgrade the NFC firmware to be compatible again with GB, so NFC will simply not work if you flash your device with GB.

PS:如果手机正在运行 ICS,请不要费心将手机降级到 GB。您无法将 NFC 固件降级以再次与 GB 兼容,因此如果您使用 GB 闪存设备,NFC 将无法正常工作。

回答by uploader33

Host card emulation is now officially supported by Android, according to http://developer.android.com/guide/topics/connectivity/nfc/hce.html

根据http://developer.android.com/guide/topics/connectivity/nfc/hce.html,主机卡模拟现在已被 Android 正式支持