- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我编写了一个 Android 应用程序,它使用 transceive()
函数与 NFC-V 卡进行通信。我的问题是那条线
byte[] response = nfcv.transceive(command)
总是抛出标签丢失异常。
有人可以帮我吗?
String action = intent.getAction();
Tag tag = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG);
NfcV nfcv = NfcV.get(tag);
if(nfcv != null) {
Toast.makeText(this, "nfcv detected", Toast.LENGTH_LONG).show();
}
try {
nfcv.connect();
Toast.makeText(this, "connected", Toast.LENGTH_LONG).show();
byte[] command = new byte[]{
(byte) 0x00, // Flags
(byte) 0x20, // Command: Read single block
(byte) 0x00, // First block (offset)
(byte) 0x04 // Number of blocks};
byte[] response = nfcv.transceive(command);
nfcv.close();
} catch(Exception e) {
Toast.makeText(this, "Error exception!", Toast.LENGTH_LONG).show();
}
我得到以下异常:
android.nfc.TagLostException: Tag was lost.
at android.nfc.TransceiveResult.getResponseOrThrow(TransceiveResult.java:48)
at android.nfc.tech.BasicTagTechnology.transceive(BasicTagTechnology.java:151)
at android.nfc.tech.NfcV.transceive(NfcV.java:115)
at com.example.nxf07589.nfc.MainActivity.onCreate(MainActivity.java:148)
at android.app.Activity.performCreate(Activity.java:6374)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1119)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2767)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2879)
at android.app.ActivityThread.access$900(ActivityThread.java:182)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1475)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:145)
at android.app.ActivityThread.main(ActivityThread.java:6141)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1399)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1194)
最佳答案
您收到 TagLostException
,因为您的命令格式错误,因此标签没有响应。
正如其名称所示,READ SINGLE BLOCK 命令(命令代码 0x20
)读取单个 block 。因此,此命令中没有长度(“ block 数”)字段。正确的命令应该是这样的:
int blockAddress = 0;
byte[] cmd = new byte[] {
(byte) 0x00, // FLAGS
(byte) 0x20, // READ_SINGLE_BLOCK
(byte)(blockAddress & 0x0ff)
};
byte[] response = nfcv.transceive(cmd);
请注意,如果标签不理解该命令(READ SINGLE BLOCK 是 ISO/IEC 15693 中的可选命令),您仍然可能会遇到 TagLostException
。
最后,某些 Android 平台无法正常运行(或根本不支持)NFC-V 的未寻址命令。因此,您可能希望改用该命令的寻址形式:
byte[] tagUid = tag.getId(); // store tag UID for use in addressed commands
int blockAddress = 0;
byte[] cmd = new byte[] {
(byte)0x20, // FLAGS
(byte)0x20, // READ_SINGLE_BLOCK
0, 0, 0, 0, 0, 0, 0, 0,
(byte)(blockAddress & 0x0ff)
};
System.arraycopy(tagUid, 0, cmd, 2, 8); // paste tag UID into command
byte[] response = nfcv.transceive(cmd);
关于Android nfcv.transceive() 抛出异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38768310/
我正在尝试在 Android 手机 (Nexus 4) 上实现不同的 NfcV 命令。目前,我正在使用 these 标签。根据数据表,它们应该支持“安静”命令。 不幸的是,我无法让下面的源代码正常工作
我正在编写一个应用程序来读取 NFC 标签的二进制信息。下面是 NFC Intent 处理函数的代码: protected void onNewIntent(@NonNull Intent inten
我编写了一个 Android 应用程序,它使用 transceive() 函数与 NFC-V 卡进行通信。我的问题是那条线 byte[] response = nfcv.transceive(comm
我必须使用 NFC-V 与传输 256 字节数据包的无线 M-Bus 协议(protocol)进行通信。谁能告诉我如何更改默认设置为 253 字节的 MaxTransceiveLength 属性? 最
我有一个 Android 应用程序可以读取 NFC 标签。在 LG Nexus 4 上一切正常,但在三星 Galaxy S5 上我只遇到 I/O 异常(在多部手机上测试过)。 因此,标签是 NfcV
我在如何解锁 NFCV 标签上的 AFI 值时遇到问题。我将 AFI 值更改为 0x27,然后是锁定 AFI 0x28。有什么方法可以解锁它吗?另外,如何检测 AFI 值是锁定还是解锁?谢谢。 最佳答
我在读取 NFC-V 标签时遇到问题。标签类型为 Tag-it HF-I Plus (TMS37112)。这是我用来读取数据的代码: private void GetTagInfo(Tag tag){
我正在开发一个有关 NFC 写入的应用程序。我们称之为 Writer...我正在将数据写入 NfcV 标签。 我试图写入的字符串是String test = "this is\ta real\ttes
我是 NFC 技术的新手! 我很难理解如何操作积木。 byte[] cmd = new byte[] { (byte)0x20, //FLAG (byte)0x21, //WR
我需要从 NfcV (ISO 15693) 标签中读取数据,我已经尝试过 Chariotsolution 的 Phonegap-Nfc 插件,但似乎这个插件只能读取 NfcV 标签中的 TagId 和
在NfcA 标准中有一个android.nfc.tech.IsoDep 类。它有一个名为:getHistoricalBytes() 的方法。如何在 NfcV 标准中获得此功能? IsoDep 类在这里
我正在尝试通过 NfcV 对象使用 WRITE MULTIPLE BLOCKS 命令将一些数据写入 NXP ICODE SLIX SL2S2002 标签 (ISO 15693): private vo
“喂,哥,怎么了?” 我在 NDEF 消息格式方面遇到了麻烦。 我浏览了 NFC 论坛,了解如何使用带有有效载荷的单个 NDEF 记录(文本 RTD)构建 NDEF 消息,因此我可以通过 I2c 对我
我正在尝试使用 NFC 从血糖仪读取数据,目前在 Android 上,还没有尝试过 iOS(没有带 NFC 的手机)。 我正在使用 react-native-nfc-manager 作为库和它附带的示
我是一名优秀的程序员,十分优秀!