SecurityException while ndef.connect() on Android 13

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.



Comments

Popular posts from this blog

Spring Elasticsearch Operations

Network Error and Timeout on Authorize.net JS

Object oriented programming concepts (OOPs)