我正在编写一个将消息写入Factory-New标签的程序
public void onNewIntent(Intent intent) {
Tag tagFromIntent = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG);
Ndef ndefTag = Ndef.get(tagFromIntent); //ndefTag will be null here
.
.
.
//read message , return if correct ,continue if empty or not correct
.
.
.
if (ndefTag == null) {
// try to format the Tag in NDEF
NdefFormatable nForm = NdefFormatable.get(tagFromIntent);
if (nForm != null) {
nForm.connect();
nForm.format(message);
nForm.close();
}
} else {
ndefTag.connect();
if (!ndefTag.isWritable()) {
Toast.makeText(getApplicationContext(), "Locked", Toast.LENGTH_SHORT).show();
locked = true;
//ndefTag.close();
} else {
ndefTag.writeNdefMessage(message);
//ndefTag.makeReadOnly();
//ndefTag.close();
Toast.makeText(getApplicationContext(), "Write success", Toast.LENGTH_SHORT).show();
}
}
}
用消息格式化标签后,我要检查消息是否正确
但是“ intent.getParcelableExtra(NfcAdapter.EXTRA_TAG)”仍然获得与没有书面消息相同的TAG,因此我必须删除标签并再次对其进行标签
是否可以调用NFC传感器再次进行标记?
还是格式化和书写的更好方法->阅读?