flutter-nfc-manager icon indicating copy to clipboard operation
flutter-nfc-manager copied to clipboard

Open nfc default NFC reader.

Open Tanvirul-swe opened this issue 2 years ago • 11 comments

This issue only occurs on Android whenever I try to scan NFC tag using my own app where it triggers the default NFC reader of the phone.

Tanvirul-swe avatar Sep 28 '22 13:09 Tanvirul-swe

you have to priorize your running app in the MainActivity.kt.

https://developer.android.com/reference/kotlin/android/nfc/NfcAdapter#enableForegroundDispatch(android.app.Activity,%20android.app.PendingIntent,%20kotlin.Array,%20kotlin.Array)

UnbreakCode avatar Oct 04 '22 07:10 UnbreakCode

We seem to experience the same issue in one of our apps.

@Tanvirul-swe have you been able to solve this?

73VW avatar Dec 02 '22 09:12 73VW

idk why to downvote my answer even if it is correct, just take a look at the example: https://github.com/okadan/nfc-manager/blob/a20a2420597ffdc545bb7321db4f0b86003124da/android/app/src/main/kotlin/com/naokiokada/nfcmanager/MainActivity.kt#L10

UnbreakCode avatar Dec 02 '22 14:12 UnbreakCode

@UnbreakCode I've downvoted because you didn't explain how to use this function.

I'll now upvote your second comment as it really provides a way to solve the problem! Thanks!

73VW avatar Dec 02 '22 15:12 73VW

I try to add these lines on MainActivity.kt but when I run the app it gives me the Error: image

idk why to downvote my answer even if it is correct, just take a look at the example: https://github.com/okadan/nfc-manager/blob/a20a2420597ffdc545bb7321db4f0b86003124da/android/app/src/main/kotlin/com/naokiokada/nfcmanager/MainActivity.kt#L10

batoul-alani avatar Jan 30 '23 12:01 batoul-alani

I try to add these lines on MainActivity.kt but when I run the app it gives me the Error: image

try to use PendingIntent.FLAG_IMMUTABLE as flagType

UnbreakCode avatar Jan 30 '23 13:01 UnbreakCode

I am not very familiar with java can you explain how will be the code?

I try to add these lines on MainActivity.kt but when I run the app it gives me the Error: image

try to use PendingIntent.FLAG_IMMUTABLE as flagType

batoul-alani avatar Jan 30 '23 13:01 batoul-alani

Thanks I solve it by using this line: val pendingIntent = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_IMMUTABLE)

I am not very familiar with java can you explain how will be the code?

I try to add these lines on MainActivity.kt but when I run the app it gives me the Error: image

try to use PendingIntent.FLAG_IMMUTABLE as flagType

batoul-alani avatar Jan 30 '23 14:01 batoul-alani

Thanks I solve it by using this line: val pendingIntent = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_IMMUTABLE)

exactly!

UnbreakCode avatar Jan 30 '23 15:01 UnbreakCode

how can we fix the same issue in ios? is there any solution for that?

batoul-alani avatar Jan 31 '23 07:01 batoul-alani

how can we fix the same issue in ios? is there any solution for that?

as far as I know it is not possible for iOS due to API limitations. But maybe the background tag reading is a "workaround", I don't know. https://developer.apple.com/documentation/corenfc/adding_support_for_background_tag_reading (even if so, you have to edit the whole flutter package natively)

UnbreakCode avatar Jan 31 '23 09:01 UnbreakCode