对于Android-App,我想在NDEF-Tag上写一条消息,并确保之后不能更改消息。显而易见的解决方案是方法makeReadOnly(),但它总是抛出没有消息(null)的java.io.IOException。 我已经尝试了以下内容:
以下是有关代码:
try {
ndefTag.connect();
if(ndefTag.canMakeReadOnly()) {
Log.d("Schuetzen", "makeReadOnly is possible");
}
else {
Log.d("Schuetzen", "makeReadOnly is not possible");
}
if(ndefTag.isWritable())
{
Log.d("Schuetzen", "Tag isWritable");
}
ndefTag.makeReadOnly();
}
catch (IOException e) {
e.printStackTrace();
Log.d("myThread", e.toString());
}
finally {
// Close connection:
try {
ndefTag.close();
Log.d("myThread", "Tag closed");
}
catch (Exception e) {
e.printStackTrace();
}
}
Logcat看起来像这样:
06-10 09:51:04.851 32274-14000/net.bits_bremen.bruenjes.gleisteinwriter D/Schuetzen﹕ makeReadOnly is possible
06-10 09:51:04.851 32274-14000/net.bits_bremen.bruenjes.gleisteinwriter D/Schuetzen﹕ Tag isWritable
06-10 09:51:04.898 32274-14000/net.bits_bremen.bruenjes.gleisteinwriter W/System.err﹕ java.io.IOException
06-10 09:51:04.898 32274-14000/net.bits_bremen.bruenjes.gleisteinwriter W/System.err﹕ at android.nfc.tech.Ndef.makeReadOnly(Ndef.java:394)
06-10 09:51:04.898 32274-14000/net.bits_bremen.bruenjes.gleisteinwriter W/System.err﹕ at net.bits_bremen.bruenjes.gleisteinwriter.myThread.doInBackground(myThread.java:34)
06-10 09:51:04.898 32274-14000/net.bits_bremen.bruenjes.gleisteinwriter W/System.err﹕ at android.os.AsyncTask$2.call(AsyncTask.java:287)
06-10 09:51:04.898 32274-14000/net.bits_bremen.bruenjes.gleisteinwriter W/System.err﹕ at java.util.concurrent.FutureTask.run(FutureTask.java:234)
06-10 09:51:04.898 32274-14000/net.bits_bremen.bruenjes.gleisteinwriter W/System.err﹕ at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
06-10 09:51:04.898 32274-14000/net.bits_bremen.bruenjes.gleisteinwriter W/System.err﹕ at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
06-10 09:51:04.898 32274-14000/net.bits_bremen.bruenjes.gleisteinwriter W/System.err﹕ at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
06-10 09:51:04.898 32274-14000/net.bits_bremen.bruenjes.gleisteinwriter W/System.err﹕ at java.lang.Thread.run(Thread.java:856)
06-10 09:51:04.898 32274-14000/net.bits_bremen.bruenjes.gleisteinwriter D/myThread﹕ java.io.IOException
06-10 09:51:04.914 32274-14000/net.bits_bremen.bruenjes.gleisteinwriter D/myThread﹕ Tag closed
任何帮助都会很棒!