阅读NFC标签的内容

时间:2012-05-02 17:47:42

标签: android tags nfc

我正在尝试在三星Galaxy Nexus S上阅读NFC标签。

    @Override
protected void onResume() {
    super.onResume();
    String nachricht = "";
    if (NfcAdapter.ACTION_NDEF_DISCOVERED.equals(getIntent().getAction())) {
        Parcelable[] rawMsgs = getIntent()
                .getParcelableArrayExtra(NfcAdapter.EXTRA_NDEF_MESSAGES);
        if (rawMsgs != null) {
            NdefMessage[] msgs = new NdefMessage[rawMsgs.length];
            for (int i = 0; i < rawMsgs.length; i++) {
                msgs[i] = (NdefMessage) rawMsgs[i];
                nachricht = nachricht + " " + msgs;
            }

            Log.e("WriteTagApp", nachricht );
        }
    }

}

使用Log.e(“WriteTagApp”,nachricht);我的应用程序将标记的消息写入调试器。 它看起来像这样:[Landroid.nfc.NdefMessage; @ 4184ce18

我似乎无法理解这里发生了什么以及如何获取消息的实际内容。 我该怎么做?

1 个答案:

答案 0 :(得分:1)

NDefMessage不是String,它是一个对象。通过连接它你只是添加其“toString”方法的输出。相反,您需要查看NdefMessage中的NdefRecords并从那里的有效负载字段中提取数据。

相关问题