您可以使用MIME类型记录将图像存储在NFC标签上。例如,如果您的图像是JPEG图像,则应使用MIME类型“ image /
jpeg”。您的NDEF记录可能如下所示:
+----------------------------------------++ MB=1, ME=1, CF=0, SR=0, IL=0, TNF=MIME ++----------------------------------------++ Type Length = 10 ++----------------------------------------++ Payload Length = N ++----------------------------------------++ image/jpeg ++----------------------------------------++ <Your image data (N bytes)> ++----------------------------------------+
在Android上,您可以使用
byte[] myImage = ...;NdefRecord myImageRecord = NdefRecord.createMime("image/jpeg", myImage);或使用的构造函数
NdefRecord:
byte[] myImage = ...;NdefRecord myImageRecord = new NdefRecord( NdefRecord.TNF_MIME_MEDIA, "image/jpeg".getBytes("US-ASCII"), null, myImage);一旦有了
TagNDEF标签的句柄(即通过接收和NFC发现意图),就可以将NDEF记录写入标签:
NdefMessage ndefMsg = new NdefMessage(new NdefRecord[] { myImageRecord });Tag tag = ...;Ndef ndefTag = Ndef.get(tag);if (ndefTag != null) { ndefTag.connect(); ndefTag.writeNdefMessage(ndefMsg); ndefTag.close();} else { NdefFormatable ndefFormatable = NdefFormatable.get(tag); if (ndefFormatable != null) { ndefFormatable.connect(); ndefFormatable.format(ndefMsg); ndefFormatable.close(); }}


