标签需要写入一条AirTouch格式记录,和一条MIME格式记录,尽量按照顺序写入。
标签格式:
标签写入代码样例:
String airTouchContent = "下载的标签内容";
String airTouchDefaultLink = "默认跳转链接";
// 若选择"标签中关联MimeType的PayLoad作为查询参数",需要以下两个变量
String airTouchJumpParamKey = "跳转链接参数";
String airTouchJumpParamValue = "跳转链接参数值";
byte[] TYPE_HW = {0x68, 0x77};
NdefMessage ndefMessage = new NdefMessage(
new NdefRecord[] {
new NdefRecord(NdefRecord.TNF_MIME_MEDIA, TYPE_HW, new byte[0], Base64.decode(airTouchContent, Base64.NO_WRAP)),
// 若选择"标签中关联MimeType的PayLoad作为查询参数",需要加入以下NdefRecord
new NdefRecord(NdefRecord.TNF_MIME_MEDIA, airTouchJumpParamKey, new byte[0], airTouchJumpParamValue),
}
);
.......
Tag tag = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG);
Ndef ndef = Ndef.get(tag);
......
ndef.writeNdefMessage(ndefMessage);