Hi I want to add nfc reader functionality in my app I am using ionic react with capcitor project
So i installed @ionic-native/nfc module in my app then phonegap-nfc but when i try to build my app and open it the app crash on startup and i got the error in android studio logcat
Here is the code snippets ,error and app configuration
const addNFCListener = async () => {
try {
await NFC.addNdefListener(
() => {
console.log(‘successfully attached ndef listener’);
},
async (err:any) => {
console.log(‘error attaching ndef listener’, err);
// Handle error
}
).subscribe(async (event) => {
console.log('received ndef message. the tag contains: ', event.tag);
const id = NFC.bytesToHexString(event.tag.id);
// Handle the tag ID as needed
// Display the tag ID in a toast or another way as needed
console.log(id);
});
} catch (error) {
console.error('Error adding NFC listener', error);
// Handle error
}
};
addNFCListener();
“@awesome-cordova-plugins/core”: “^5.40.0”,
“@awesome-cordova-plugins/firebase-authentication”: “^5.41.0”,
“@awesome-cordova-plugins/network”: “^6.2.0”,
“@awesome-cordova-plugins/pdf-generator”: “^5.41.0”,
“@awesome-cordova-plugins/photo-viewer”: “^5.39.1”,
“@awesome-cordova-plugins/sign-in-with-apple”: “^5.41.0”,
“@awesome-cordova-plugins/splash-screen”: “^6.2.0”,
“@capacitor-community/facebook-login”: “^3.3.0”,
“@capacitor-community/native-market”: “^4.0.0”,
“@capacitor/android”: “^5.0.0”,
“@capacitor/app”: “^5.0.0”,
“@capacitor/core”: “^5.0.0”,
“@capacitor/filesystem”: “^5.0.0”,
“@capacitor/haptics”: “^5.0.0”,
“@capacitor/ios”: “^5.0.0”,
“@capacitor/keyboard”: “^5.0.0”,
“@capacitor/push-notifications”: “^5.0.0”,
“@capacitor/status-bar”: “^5.0.0”,
“@ionic-native/nfc”: “^5.36.0”,
“phonegap-nfc”: “^1.2.0”,
FATAL EXCEPTION: main
Process: com.realornot.app, PID: 16105
java.lang.RuntimeException: Unable to resume activity {com.realornot.app/com.realornot.app.MainActivity}: java.lang.IllegalArgumentException: com.realornot.app: Targeting S+ (version 31 and above) requires that one of FLAG_IMMUTABLE or FLAG_MUTABLE be specified when creating a PendingIntent.
Strongly consider using FLAG_IMMUTABLE, only use FLAG_MUTABLE if some functionality depends on the PendingIntent being mutable, e.g. if it needs to be used with inline replies or bubbles.
at android.app.ActivityThread.performResumeActivity(ActivityThread.java:4773)
at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:4806)
at android.app.servertransaction.ResumeActivityItem.execute(ResumeActivityItem.java:54)
at android.app.servertransaction.ActivityTransactionItem.execute(ActivityTransactionItem.java:45)
at android.app.servertransaction.TransactionExecutor.executeLifecycleState(TransactionExecutor.java:176)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:97)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2307)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loopOnce(Looper.java:201)
at android.os.Looper.loop(Looper.java:288)
at android.app.ActivityThread.main(ActivityThread.java:7872)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:936)
Caused by: java.lang.IllegalArgumentException: com.realornot.app: Targeting S+ (version 31 and above) requires that one of FLAG_IMMUTABLE or FLAG_MUTABLE be specified when creating a PendingIntent.
Strongly consider using FLAG_IMMUTABLE, only use FLAG_MUTABLE if some functionality depends on the PendingIntent being mutable, e.g. if it needs to be used with inline replies or bubbles.
at android.app.PendingIntent.checkFlags(PendingIntent.java:401)
at android.app.PendingIntent.getActivityAsUser(PendingIntent.java:484)
at android.app.PendingIntent.getActivity(PendingIntent.java:470)
at android.app.PendingIntent.getActivity(PendingIntent.java:434)
at com.chariotsolutions.nfc.plugin.NfcPlugin.createPendingIntent(NfcPlugin.java:486)
at com.chariotsolutions.nfc.plugin.NfcPlugin.startNfc(NfcPlugin.java:534)
at com.chariotsolutions.nfc.plugin.NfcPlugin.onResume(NfcPlugin.java:814)
at org.apache.cordova.PluginManager.onResume(PluginManager.java:287)
at com.getcapacitor.cordova.MockCordovaWebViewImpl.handleResume(MockCordovaWebViewImpl.java:155)
at com.getcapacitor.Bridge.onResume(Bridge.java:1271)
at com.getcapacitor.BridgeActivity.onResume(BridgeActivity.java:85)
at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1564)
at android.app.Activity.performResume(Activity.java:8437)
at android.app.ActivityThread.performResumeActivity(ActivityThread.java:4763)
… 13 more