-
Notifications
You must be signed in to change notification settings - Fork 68
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
No event firing when NFC is scanned - Android #111
Comments
Furthermore, the NFC card I'm scanning is empty. When I scan it with my phone it says "New tag scanned" and "Empty tag". Is it possible that the issue is due to the card not being formatted a certain way? I also gave my friend the project code and he tried it on his phone and it successfully scanned a previously encoded card, receiving event "Current_OnMessageReceived". |
I was just dealing with this issue as well. The way I solved it was to put public MyPage() {
InitializeComponent();
CrossNFC.Current.StartListening();
}
protected override void OnAppearing() {
CrossNFC.Legacy = false;
CrossNFC.Current.OnMessageReceived += Current_OnMessageReceived;
...
}
private void Current_OnMessageReceived(ITagInfo tagInfo) {
...
} Worth noting, I ran into this issue while trying to solve a different problem of cards being scanned multiple times when held to the back of the phone. If you run into this issue, the way I solved it was to make sure to stop CrossNFC from listening to scans in your pages protected override void OnDisappearing() {
CrossNFC.Current.StopListening();
...
} |
@iaps can you please try the solution above or better format and share more of your code. It’s not enough to debug the issue |
Thanks @wfahnestock. I put CrossNFC.Current.StartListening() in my ContentPage constructor, but when launched it said: System.NullReferenceException: 'Object reference not set to an instance of an object.' I should note that I tried with an older phone and everything worked as it should (NFC reader read the card). But on my Galaxy Note10+ the card wouldn't read or be recognized within the app; NFC cards are able to be read with the app closed - on main home screen. |
So @iaps you’re saying that you used the example in this repository and you had the error on one device but not the other? |
I'm saying that I used my original solution on a different phone, and everything worked. It doesn't work on my Galaxy Note10+ @wfahnestock solution didn't work on either device since it threw a NullReferenceException when in the constructor. |
Exactly right. |
On your Galaxy Note 10+ did you have Developer Options and NFC turned on in the Settings? |
I do indeed. I can scan an NFC when the app is closed, and since I'm using my phone to debug, developer options is enabled. |
I have the same issue. For debugging I use the Xiaomi Redmi Note 10 5G (M2103K19G). |
Description
I have copied the code setup as described. The following are all true: CrossNFC.IsSupported, CrossNFC.Current.IsAvailable, CrossNFC.Current.IsEnabled, CrossNFC.Current.IsWritingTagSupported
All events subscribed in OnAppearing:
CrossNFC.Legacy = false;
// Event raised when a ndef message is received.
CrossNFC.Current.OnMessageReceived += Current_OnMessageReceived;
// Event raised when a ndef message has been published.
CrossNFC.Current.OnMessagePublished += Current_OnMessagePublished;
// Event raised when a tag is discovered. Used for publishing.
CrossNFC.Current.OnTagDiscovered += Current_OnTagDiscovered;
// Event raised when NFC listener status changed
CrossNFC.Current.OnTagListeningStatusChanged += Current_OnTagListeningStatusChanged;
// Android
CrossNFC.Current.OnNfcStatusChanged += Current_OnNfcStatusChanged;
Listening: CrossNFC.Current.StartListening();
Perms are set:
MainActivity has CrossNFC.Init(this); in OnCreate, CrossNFC.OnResume(); in OnResume, and CrossNFC.OnNewIntent(intent); in OnNewIntent.
Steps to Reproduce
Expected Behavior
Actual Behavior
Basic Information
Screenshots
Reproduction Link
The text was updated successfully, but these errors were encountered: