Java 如何使NFC标记具有写保护?

Java 如何使NFC标记具有写保护?,java,android,nfc,Java,Android,Nfc,我正在构建一个从NFC标记写入和读取的应用程序,但我需要在写入数据后不修改数据。 我尝试了MakeReadOnly(),但我不知道为什么它不起作用 protected void onNewIntent(Intent intent) { super.onNewIntent(intent); if(intent.hasExtra(NfcAdapter.EXTRA_TAG)) { Toast.makeText(this,"NFC intent!

我正在构建一个从NFC标记写入和读取的应用程序,但我需要在写入数据后不修改数据。 我尝试了MakeReadOnly(),但我不知道为什么它不起作用

     protected void onNewIntent(Intent intent) {
    super.onNewIntent(intent);
    if(intent.hasExtra(NfcAdapter.EXTRA_TAG))
    {
            Toast.makeText(this,"NFC intent!",Toast.LENGTH_SHORT).show();// After detecting a tag on my system, I can get an tag object to write or read from it
            Tag tag = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG);
            NdefMessage ndefMessage = creatNdefMessage(StudentId.getText()+"");
            writeNdefMessage(tag,ndefMessage);
        // it writes on the tag but cannot makeit read only !!!

       try{ Ndef ndef = Ndef.get(tag);
        if (ndef != null) {
            ndef.connect();
            if (ndef.canMakeReadOnly()) {
              Toast.makeText(this,"can make it read only !",Toast.LENGTH_SHORT).show();
               ndef.makeReadOnly();
              }
             ndef.close();
          }
      } catch (IOException e) {
         e.printStackTrace();
     }

     }
       }
在这段代码中,我可以检查它是否访问if语句(ndef.canMakeReadOnly()),这意味着只有在调用MakeReadOnly方法时,标记才可以是红色的,但在运行它之后,我仍然可以覆盖标记


请帮助..

canMakeReadOnly()
实际上并没有尝试将标记设置为只读,它只对适当的位执行检查。我会检查
makeReadOnly()
的返回值,看看它是否成功。看,谢谢,是的,我知道这个信息,canMakeReadOnly()方法返回(true),这意味着如果我调用MakeReadOnly(),它可以是只读的,但实际上它不工作@henrycjc和我也检查了网站。这是哪种标签类型?Mifare 1k S50 MF1