NDEF消息与Android的HCE [英] NDEF Message with HCE Android
问题描述
我想模拟主机卡与Android上的HCE功能。对于我扩展了服务类HostApduService并覆盖下面的方法:
I wanna emulate a host card with the HCE feature from Android. For that I extend the service class HostApduService and overwrite following method:
public byte[] processCommandApdu(byte[] commandApdu, Bundle extras) {
if (Arrays.equals(SELECT_APDU, commandApdu)) {
NdefMessage message = new NdefMessage(new NdefRecord [] {NdefRecord.createTextRecord("en", "test"});
return message.toByteArray();
} else {
return UNKNOWN_CMD_SW;
}
}
通过第二装置其可能从HCE服务接收数据。问题是,我总是收到A型的标签,但我需要一个NDEF消息。
With a second device its possible to receive data from the HCE Service. The problem is that I always receive "Type A" Tag, but I need a NDEF Message.
任何人可以帮助我吗?
推荐答案
仿效是使用Android HCE检测为NDEF标签的标签是不作为响应于一个SELECT APDU发送NDEF消息一样简单。你会需要实现NFC论坛类型4标签操作规范。你可以从 NFC论坛网站该规范。
Emulating a tag that is detected as NDEF tag using Android HCE is not as simple as sending an NDEF message in response to a SELECT APDU. You would need to implement the NFC Forum Type 4 Tag Operation specification. You can get that specification from the NFC Forum website.
基本上你就需要为AID注册HCE服务 D2760000850101
实现了几个APDU命令,以便读者端用来访问类型4标签:
Basically you would need to register a HCE service for the AID D2760000850101
that implements a couple of APDU commands that the reader-side uses to access a Type 4 tag:
-
选择NDEF标签应用
SELECT NDEF tag application
00 A4 04 00 07 D2760000850101 [00]
选择能力的容器
SELECT capability container
00 A4 04 0C 02 E103
选择NDEF数据文件
SELECT NDEF data file
00 A4 04 0C 02 xxyy
其中, XXYY
是NDEF数据文件的文件ID作为能力容器指定。
Where xxyy
is the file ID of the NDEF data file as specified in the capability container.
READ BINARY(从功能容器或NDEF数据文件为准当前选定的读取数据)
READ BINARY (for reading data from capability container or NDEF data file, whichever is currently selected)
00 B0 xx yy zz
其中, XX YY
是抵消和 ZZ
是要读取的字节数。阅读p>
Where xx yy
is the offset to read at and zz
is the number of bytes to read.
这篇关于NDEF消息与Android的HCE的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!