- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在开发一个有关 NFC 写入的应用程序。我们称之为 Writer...我正在将数据写入 NfcV 标签。
我试图写入的字符串是String test = "this is\ta real\ttestcase\tyou tag";
为了写入数据,我使用 NfcV 的 transceive
方法。这就是我的编写方法:
public static String bytesToHex(byte[] bytes) {
StringBuilder sb = new StringBuilder(bytes.length * 2);
Formatter formatter = new Formatter(sb);
for (byte b : bytes) {
formatter.format("%02X", b);
}
formatter.close();
return sb.toString();
}
public void write(View v) {
try {
String[] tagInfoArray = new String[tagData.size()];
for (int i = 0; i < tagData.size(); i++)
tagInfoArray[i] = tagData.get(i).getText().toString();
String tagInfo = join(tagInfoArray, "\t");
//String test = "this is\ta real\ttestcase\tyou tag";
writeTag(tag, tagInfo);
} catch (NullPointerException e) {
Toast.makeText(this, "How about providing a tag!",
Toast.LENGTH_LONG).show();
} finally {
write.setBackgroundResource(R.layout.bluebutton);
}
}
public String join(String[] input, String delim) {
String output = "";
if (input.length > 0)
output += input[0];
if (input.length > 1)
for (int i = 1; i < input.length; i++)
output += delim + input[i];
return output;
}
public void exitButton(View v) {
this.foreground.disableForeground();
System.exit(0);
}
public void writeTag(Tag tag, String data) {
NfcV myTag = NfcV.get(tag);
try {
myTag.connect();
if (myTag.isConnected()) {
byte[] info = data.getBytes();
int dataLength = info.length;
if (data.length()/4 <= 64){
byte[] args = new byte[15];
args[0] = 0x20;
args[1] = 0x21;
byte[] id = tag.getId();
for (int o=0; o<8; o++)
args[o+2] = id[o];
for (int i = 0; i<64; i++) {
args[10] = (byte) i;
args[11] = 0x00;
args[12] = 0x00;
args[13] = 0x00;
args[14] = 0x00;
byte[] out = myTag.transceive(args);
String out2 = bytesToHex(out);
System.out.println("1:.. " + printHex(out2));
}
for (int i = 0; i<=dataLength/4; i++) {
args[10] = (byte) i;
args[11] = getByte(info, (i*4)+0);
args[12] = getByte(info, (i*4)+1);
args[13] = getByte(info, (i*4)+2);
args[14] = getByte(info, (i*4)+3);
byte[] out = myTag.transceive(args);
String out2 = bytesToHex(out);
System.out.println("2:.. " + printHex(out2));
}
}
}
} catch (IOException e) {
System.out.println(e.getMessage());
} finally {
if (myTag != null) {
try {
myTag.close();
} catch (IOException e) {
System.out.println(e.getMessage());
}
}
}
}
public static byte getByte(byte[] input, int key){
try {
return input[key];
} catch (Exception e){
return (byte)0x00;
}
}
public String printByte(byte[] input){
try {
return new String(input, "UTF-8");
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return "";
}
public String printHex(String input){
return input;
}
所以当我写东西的时候,结果并不是我所期望的。它要么根本不写入,要么只写入部分内容,但不会覆盖标签上之前的内容。
这是输出:
11-05 15:32:33.139: I/System.out(1390): 1:.. 00
11-05 15:32:33.249: I/System.out(1390): 1:.. 00
11-05 15:32:33.349: I/System.out(1390): 1:.. 00
11-05 15:32:33.449: I/System.out(1390): 1:.. 00
11-05 15:32:33.549: I/System.out(1390): 1:.. 00
11-05 15:32:33.649: I/System.out(1390): 1:.. 00
11-05 15:32:33.759: I/System.out(1390): 1:.. 00
11-05 15:32:33.859: I/System.out(1390): 1:.. 00
11-05 15:32:33.959: I/System.out(1390): 1:.. 00
11-05 15:32:34.059: I/System.out(1390): 1:.. 00
11-05 15:32:34.159: I/System.out(1390): 1:.. 00
11-05 15:32:34.259: I/System.out(1390): 1:.. 00
11-05 15:32:34.359: I/System.out(1390): 1:.. 00
11-05 15:32:34.469: I/System.out(1390): 1:.. 00
11-05 15:32:34.569: I/System.out(1390): 1:.. 00
11-05 15:32:34.669: I/System.out(1390): 1:.. 00
11-05 15:32:34.769: I/System.out(1390): 1:.. 00
11-05 15:32:34.869: I/System.out(1390): 1:.. 00
11-05 15:32:34.979: I/System.out(1390): 1:.. 00
11-05 15:32:35.079: I/System.out(1390): 1:.. 00
11-05 15:32:35.179: I/System.out(1390): 1:.. 00
11-05 15:32:35.289: I/System.out(1390): 1:.. 00
11-05 15:32:35.389: I/System.out(1390): 1:.. 00
11-05 15:32:35.489: I/System.out(1390): 1:.. 00
11-05 15:32:35.589: I/System.out(1390): 1:.. 00
11-05 15:32:35.689: I/System.out(1390): 1:.. 00
11-05 15:32:35.789: I/System.out(1390): 1:.. 00
11-05 15:32:35.889: I/System.out(1390): 1:.. 00
11-05 15:32:35.989: I/System.out(1390): Transceive failed
最佳答案
总结第一篇文章中的各种问题:
NfcV.getMaxTransceiveLength()
返回有关在一个命令/一个响应中可以交换的最大字节数的信息。它不提供有关标签大小的信息!Tag.getId()
来获取 ID 并根据标签制造商的数据表)。另一种方法是读取直到第一个 IOException 并从该信息推断标签大小。您可以稍后重新连接标签以继续读取/写入。但是,请记住,任何其他通信中断(例如,用户未正确扫描标签)也可能导致 IOExceptions,并可能因此伪造您的估计标签大小。关于java - 使用 NfcV tag.transceive 写入标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19770400/
我正在尝试在 Samsung Galaxy S3 和支持 NfcA 和 IsoDep (Mifare DESFire EV1) 的智能卡之间进行通信。为此,我启用了 forgeground dispa
我编写了一个 Android 应用程序,它使用 transceive() 函数与 NFC-V 卡进行通信。我的问题是那条线 byte[] response = nfcv.transceive(comm
我正在开发一个有关 NFC 写入的应用程序。我们称之为 Writer...我正在将数据写入 NfcV 标签。 我试图写入的字符串是String test = "this is\ta real\ttes
我正在开发一个可以在 NFC 标签上读写的 android 应用程序。我可以毫无问题地读取我已经写过东西的标签,但是当我使用空白标签时,我很难读取十六进制代码中标签的 UID。 我使用的是 mifar
我使用 NFC 标签,它发现了 ISO、NFCA 和 NDEF 技术。有信息要从芯片读取,我尝试访问内存,但我用来与TAG通信的大多数命令都以响应[110, 0] 字节。我找不到这是什么意思,其中一些
我正在尝试将我的 Android 平板电脑连接到使用 NFC 的设备并从该设备检索数据。 我尝试过的 按照 nfc_device_detection_1.01.pdf 中的说明发送命令(第四章) tr
我正在尝试模拟 PoS,销售点 :),系统并使用在 2013 Nexus 7(无安全元件)v4.4.2 上运行的 Google 钱包完成交易。 我的 PoS 原型(prototype)也在 2013
最近我正在尝试读取一张 MifareClassic 1K 卡。在了解到只有某些带有 NXP 芯片的手机能够读取这些标签的事实后,我遇到了一个新问题。 我正在尝试读取的卡片会抛出标题中提到的错误,但仅在
我试图在我的空 NTAG213 标签上设置密码,但是当我开始编写 PACK 和 PWD 时,我的应用程序崩溃了,没有抛出任何异常。我确实让我的应用程序足够远,可以编写有效的 NDEF 消息并读取它们,
我有许多新手 NfcA 问题。在 docs 和网络上的其他地方似乎对此几乎没有指导,所以我希望没有人介意我在这里将一些基本问题串在一起...... 我正在使用 nfcA.transceive() 将数
我仍在尝试模拟销售点 (POS) 系统并使用 Google 钱包完成交易。我在堆栈溢出方面得到了很好的答案。参见 Android isoDep.transceive on Generate AC co
我是一名优秀的程序员,十分优秀!