Skip to main content
hagbard
Associate II
March 22, 2023
Solved

ST25NFCApplicationV3.7.0 Crashes on Android 13 (Pixel6a)

  • March 22, 2023
  • 11 replies
  • 6026 views

Hello,

st25nfcApplication_V3.7.0 is crashing on my Pixel6A (Android13) caused by the following source:

E/AndroidRuntime: FATAL EXCEPTION: AsyncTask #1

   Process: com.st.st25nfc.dbg, PID: 1098

   java.lang.RuntimeException: An error occurred while executing doInBackground()

       at android.os.AsyncTask$4.done(AsyncTask.java:415)

       at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:381)

       at java.util.concurrent.FutureTask.setException(FutureTask.java:250)

       at java.util.concurrent.FutureTask.run(FutureTask.java:269)

       at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:305)

       at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1137)

       at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:637)

       at java.lang.Thread.run(Thread.java:1012)

    Caused by: java.lang.SecurityException: Permission Denial: Tag ( ID: 2E D4 4E 50 00 27 02 E0 ) is out of date

       at android.nfc.Tag.getTagService(Tag.java:381)

Could this be the the reasion: ???

Catch a SecurityException that was introduced in AOSP commit 113f3a4. It is thrown when an NFC tag is removed.

https://github.com/open-keychain/open-keychain/pull/2804

Does anyone have a solution ?

This topic has been closed for replies.
Best answer by Olivier L

Hi,

To fix this issue, you will need the latest "Android Reader Interface" (version >= 1.0.9). It can be downloaded from ST25SDK package. This is the file named "st25_android_reader_interface.aar".

Then, in your application, you should find the code processing the Android Intent indicating a new Tag Handle (NfcAdapter.EXTRA_TAG) and you should update the NFCTag object that you are using. This is the lines 35 to 45:

public void onResume() {
 super.onResume();
 
 NFCTag currentTag = (NFCTag) MainActivity.getTag();
 mIsActive = true;
 
 boolean tagChanged = tagChanged(this, currentTag);
 
 if (mTagTapedListener != null) {
 mTagTapedListener.tagTaped(tagChanged);
 }
 
 if (tagChanged) {
 Log.d(TAG, "=== Tag has changed : Restart MainActivity ===");
 
 // Tag has changed. We want to do the following actions;
 // - Go back to the MainActivity and flush the activity stack history (MainActivity will be seen as the sole activity launched)
 // - The intent should contain the NFC Intent details so that MainActivity can process it and do the right actions.
 
 // Get current NFC intent and retrieve the NFC information (NfcAdapter.EXTRA_TAG)
 Intent nfcIntent = getIntent();
 Tag androidTag = nfcIntent.getParcelableExtra(NfcAdapter.EXTRA_TAG);
 
 // Create an intent to start the MainActivity
 Intent intent = new Intent(this, MainActivity.class);
 
 // Attach the NFC information to this intent
 intent.putExtra(NfcAdapter.EXTRA_TAG, androidTag);
 
 // Set the flags to flush the activity stack history
 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
 
 startActivity(intent);
 } else {
 // The same tag has been tapped
 // If a new androidTag handle is available we should update the AndroidReaderInterface of the currentTag
 Intent intent = getIntent();
 Tag newAndroidTag = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG);
 if (newAndroidTag != null) {
 if (currentTag != null) {
 AndroidReaderInterface androidReaderInterface = (AndroidReaderInterface) currentTag.getReaderInterface();
 Tag currentAndroidTag = androidReaderInterface.getAndroidTag();
 if (newAndroidTag != currentAndroidTag) {
 Log.w(TAG, "Update of androidTag handle: " + newAndroidTag);
 androidReaderInterface.setAndroidTag(newAndroidTag);
 }
 }
 }
 }
 
 Log.v(TAG, "enableForegroundDispatch");
 mNfcAdapter.enableForegroundDispatch(this, mPendingIntent, null /*nfcFiltersArray*/, null /*nfcTechLists*/);
 }

11 replies

Olivier L
ST Employee
April 17, 2024

Hi,

I'm glad to see that your issue is now fixed.

Regards