I have this code (Java) to write nfc tags:
private Tag tag;
@Override
protected void onNewIntent(Intent intent) {
if (NfcAdapter.ACTION_TAG_DISCOVERED.equals(intent.getAction())) {
tag = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG);
}
}
private boolean write(String message, Tag tag) throws IOException, FormatException {
Ndef ndef = Ndef.get(tag);
ndef.connect();
if (ndef.isWritable()) {
ndef.writeNdefMessage(message);
}
ndef.close();
}
Said code was working until I updated my app to be compatible with the latest versions of Android.
Now running this code on Android 13 gives me the following exception:
java.lang.SecurityException: Permission Denial: Tag ( ID: XX XX XX XX XX XX XX ) is out of date
at android.nfc.Tag.getTagService(Tag.java:388)
at android.nfc.tech.BasicTagTechnology.connect(BasicTagTechnology.java:73)
at android.nfc.tech.Ndef.connect(Ndef.java:71)
I understand that there is some compatibility problem but I don't know what exactly.
I am thankful for any kind of help.
UPDATE: Thanks to your feedback and some additional research I came to a solution.
I was triggering this NFC write from the onNewIntent function. It seems that it is no longer possible due to some security issues. I solved it by triggering this NFC write from the onResume function instead.
Thank you all for your help.