Skip to main content
Eraqu
Associate
July 17, 2019
Solved

Cannot have access to writable memory or it's size (Android App). error :TAG_CMD_CALLED_FROM_UI_THREAD

  • July 17, 2019
  • 2 replies
  • 1079 views

I'm working on an android app and using your SDK (using version 1.5.1).

The app can read the Tag name and UID, however, I have not been able to make it read the memory size or the content of the NDEF message.

String tagName = mNfcTag.getName();
TextView tagNameTextView = (TextView) findViewById(R.id.tagNameTextView);
tagNameTextView.setText(tagName);
 
String uidString = mNfcTag.getUidString();
TextView uidTextView = (TextView) findViewById(R.id.uidTextView);
uidTextView.setText(uidString);
 
mTagSize = ": " + String.valueOf(mNfcTag.getMemSizeInBytes()) + " bytes";
 
TextView tagMemSizeTextView = (TextView) findViewById(R.id.tagMemSizeTextView);
tagMemSizeTextView.setText(String.valueOf(mTagSize));
 
NDEFMsg ndefContent=nfcTag.readNdefMessage();
String contenu=ndefContent.toString();
 
TextView ndefTextView=(TextView) findViewById(R.id.ndefScanTextView);
ndefTextView.setText(contenu);

mNfcTag.getMemSizeInBytes() on line 9 and nfcTag.readNdefMessage() on line 14 both create an error while mNfcTag.getName() and mNfcTag.getUidString(); both work perfectly.

What is required in order for those commands to work, that I possibly missed/didn't think of?

Regards,

Edwin

    This topic has been closed for replies.
    Best answer by Damien G.

    Hello Edwin,

    the error that you report indicates that the command sent to the tag is launched from the Android's UI thread.

    The Android reader interface implementation forbids this because it makes the UI unresponsive until the tag sends the response back.

    The Android Demo App documentation located in folder integration\android\documentation of the ST25SDK explains all this and recommends that you use an AsyncTask to do the job.

    You will also find there an example of a Ndef Write command.

    I am attaching the guide to this message for your convenience.

    Regards,

    Damien

    2 replies

    Eraqu
    EraquAuthor
    Associate
    July 18, 2019

    Precision:

    Error is "TAG_CMD_CALLED_FROM_UI_THREAD"

    Damien G.Best answer
    ST Employee
    July 18, 2019

    Hello Edwin,

    the error that you report indicates that the command sent to the tag is launched from the Android's UI thread.

    The Android reader interface implementation forbids this because it makes the UI unresponsive until the tag sends the response back.

    The Android Demo App documentation located in folder integration\android\documentation of the ST25SDK explains all this and recommends that you use an AsyncTask to do the job.

    You will also find there an example of a Ndef Write command.

    I am attaching the guide to this message for your convenience.

    Regards,

    Damien