我已经开始了解更多关于 AAR 和 NFC 的知识,并发现这段简洁的代码可以正常工作。但是,我很难理解它的真正作用以及它是否已经将 AAR 添加到 NDEF 消息中。有人可以指导我哪一行代码做什么?非常感谢!
private NdefMessage getTagAsNdef() {
boolean addAAR = false;
String uniqueId = "ichatime.com";
byte[] uriField = uniqueId.getBytes(Charset.forName("US-ASCII"));
byte[] payload = new byte[uriField.length + 1]; //add 1 for the URI Prefix
payload[0] = 0x01; //prefixes http://www. to the URI
System.arraycopy(uriField, 0, payload, 1, uriField.length); //appends URI to payload
NdefRecord rtdUriRecord = new NdefRecord(
NdefRecord.TNF_WELL_KNOWN, NdefRecord.RTD_URI, new byte[0], payload);
if(addAAR) {
// note: returns AAR for different app (nfcreadtag)
return new NdefMessage(new NdefRecord[] {
rtdUriRecord, NdefRecord.createApplicationRecord("com.example.ponpon")
});
} else {
return new NdefMessage(new NdefRecord[] {
rtdUriRecord});
}
}