【发布时间】:2015-03-19 11:47:45
【问题描述】:
我正在使用 Eclipse-Android 并创建一个应该使用此代码发送纯文本的应用程序:
编辑:
private void write(String text, Tag tag) throws IOException, FormatException {
NdefRecord[] records = { createTextRecord(text, "yes") };
NdefMessage message = new NdefMessage(records);
// Get an instance of Ndef for the tag.
Ndef ndef = Ndef.get(tag);
// Enable I/O
ndef.connect();
// Write the message
ndef.writeNdefMessage(message);
// Close the connection
ndef.close();
}
private NdefRecord createRecord(String text) throws UnsupportedEncodingException {
String lang = "en";
byte[] textBytes = text.getBytes();
byte[] langBytes = lang.getBytes("US-ASCII");
int langLength = langBytes.length;
int textLength = textBytes.length;
byte[] payload = new byte[1 + langLength + textLength];
// set status byte (see NDEF spec for actual bits)
payload[0] = (byte) langLength;
// copy langbytes and textbytes into payload
System.arraycopy(langBytes, 0, payload, 1, langLength);
System.arraycopy(textBytes, 0, payload, 1 + langLength, textLength);
NdefRecord recordNFC = new NdefRecord(NdefRecord.TNF_WELL_KNOWN, NdefRecord.RTD_TEXT, new byte[0], payload);
return recordNFC;
}
但我用我的 arduino 读到的是包名和 Google Play 商店链接。如何配置它以使读取的唯一消息是纯文本?
【问题讨论】:
-
您不能发送纯文本。您只能传送一个或多个 NDEF 记录。
-
这是否意味着我只能发送播放商店链接或软件包名称?
-
您的问题不包含相关代码!
createRecord()在哪里调用?您如何激活/注册 Beam?你用的是什么设备? -
我编辑我的帖子并添加其他代码
-
那还不是相关代码!您是否在 Arduino 端实施 SNEP/Android Beam?
Ndef ndef = Ndef.get(tag);看起来好像您正试图以 NFC 标签的形式访问 Arduino 端——这肯定不是 Android Beam 的代码。
标签: android nfc ndef android-beam