简体   繁体   English

如何在Android手机上模拟nfc-tag

[英]How to emulate a nfc-tag on an android phone

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. 我有一个Android手机(nexus s,sdk v15),它将使用tag-emulation将字符串发送到以nfc-reader / writer-mode运行的开发板。 I know this is not officially supported by android, so I could do it natively by accessing the driver directly(?). 我知道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. 我也知道这可以通过p2p的android api方法来完成,但是这对板子来说效果不好,所以我试试这个方法。

For a device running stock KitKat 4.4 对于运行库存KitKat 4.4的设备

With Android KitKat 4.4 the ability to have the phone act as an NFC card is built into the operating system so you no longer have to rely on Cyanogenmod or a custom ROM. 使用Android KitKat 4.4操作系统内置了将手机充当NFC 的功能,因此您不再需要依赖Cyanogenmod或自定义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 reader so I'd definitely recommend this option if you can get 4.4 on your device. 它本身不会让手机充当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 device and 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. 他们确实要求将2.3.4 Gingerbread ROM闪存到你的设备以及一些其他补丁以启用卡仿真功能,所以如果你不愿意这样做那么它们将没有多大用处,但就我而言意识到这是让它运转的唯一方法。 I haven't actually tested this myself but user comments suggest it works. 我自己没有亲自测试过,但用户评论表明它有效。

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: 以下是原始论坛帖子的链接,其中包含2.3.4补丁以启用它:
http://forum.xda-developers.com/showthread.php?t=1281946 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 / Android的开发者/ 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“。

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 eg https://stackoverflow.com/a/10506299/1202968 . 这不是太难,请参阅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. 获得控制权的唯一方法是在Secure Element上创建和安装Java Card applet。 However, to be able to do that you need acces to secret authentication keys that are only known to Google. 但是,为了能够这样做,您需要访问仅为Google所知的秘密身份验证密钥。

PS: Don't bother with downgrading your phone to GB if it is running ICS. PS:如果正在运行ICS,请不要将手机降级为GB。 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. 您无法将NFC固件降级为与GB再次兼容,因此如果使用GB刷新设备,NFC将无法正常工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM