Android NfcV获取信息命令仅返回一个字节 [英] Android NfcV get information command returns only one byte

查看:202
本文介绍了Android NfcV获取信息命令仅返回一个字节的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个用于读取NFC标签的二进制信息的应用程序.这是NFC意向处理函数的代码:

I'm writing an app for reading binary infos of NFC tags. Here's the code of the NFC intent handler function:

protected void onNewIntent(@NonNull Intent intent)
{
    try
    {
        Tag    tag     = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG);
        NfcV   nfcV    = NfcV.get(tag);
        byte[] cmdInfo = new byte[]{(byte) 0x02, (byte) 0x2b}; // 'Get info' command
        byte[] answer  = nfcV.transceive(cmdInfo); // Read info from tag.

        ...
    }
    catch(IOException e)
    {
        ...
    }
}

如果我运行此功能以读取Samsung S3 Neo上的NFC标签,则一切正常,答案变量将填入预期的数据:

If I run this function reading an NFC tag on a Samsung S3 Neo everything works fine, the answer variable is filled with the expected data:


00 04 4B A0 14 01 00 A0 07 E0 F3 07

但是,如果我运行相同的功能来读取Huawei P8lite上的相同NFC标签,则答案变量仅填充一个字节:

Howewer if I run the same function reading the same NFC tag on a Huawei P8lite the answer variable is filled with only one byte:


03

如果出现错误,ISO 15693-3标准表示我应该收到类似的信息

In case of an error, the ISO 15693-3 standard says that I should receive something like


01 03

即至少两个字节,其中第二个字节是错误代码.因此,我实际上得到的答案在理论上是不可能的.

I.e. at least two bytes, where the second byte is the error code. So the answer I'm actually getting is theoretically not possible.

我做错了什么?是否取决于移动硬件?我该如何解决?

What am I doing wrong? Does it depend on the mobile hardware? And how can I fix it?

推荐答案

由于未使用寻址命令(未设置Address_flag,因此请求中没有UID字段).如果标签不支持可选命令(甚至没有错误代码),您将根本不会收到任何共鸣.因此,根据标准,您既不会收到03也不会收到01 03.

Since you are not using an addressed command (Address_flag not set, no UID field in request). You should not receive any resonse at all if an optional command is not supported by the tag (not even an error code). Hence you should neither receive 03 nor 01 03 according to the standard.

请注意,涉及ISO/IEC 15693的Android设备中的NFC芯片组通常具有局限性,并且不支持完整的标准.例如,已知某些芯片组的未寻址命令有问题.您可以使用命令的寻址版本来解决此问题:

Note that NFC chipsets in Android devices often have limitations when it comes to ISO/IEC 15693 and do not support the complete standard. For instance, some chipsets are known to have issues with non-addressed commands. You could work around that by using the addressed version of the command:

Tag tag = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG);
NfcV nfcV = NfcV.get(tag);
byte[] cmdInfo = new byte[]{
        (byte)0x20,
        (byte)0x2B,
        (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00 };
System.arraycopy(tag.getId(), 0, cmdInfo, 2, 8);
byte[] answer = nfcV.transceive(cmdInfo);

您可能还想对Data_rate_flag进行不同的设置测试,因为设备上的NFC芯片组可能会出现VICC以高数据速率响应的问题.

You might also want to test with different settings for the Data_rate_flag since the NFC chipset on your device might have problems with VICCs responding with at high data rate.

这篇关于Android NfcV获取信息命令仅返回一个字节的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆