Forum Xamarin.Android

Launching a Xamarin app when RFID / NFC tag is detected.

ShayOhayonShayOhayon USMember ✭✭✭

I tried using NFCForms (https://www.nuget.org/packages/NFCForms/) to read RFID tags (MIFARE classic in my case).
I successfully managed to get the intent callback when the app is up&running (and read the serial number), but the app would not launch when it is closed.
I went over all the recommended tips in the forums already:
1) Adding LaunchMode = LaunchMode.SingleTop
2) Adding IntentFilter
3) Adding Tech filter resource
But the app will still not launch.

Can someone please post a working example?

Tagged:

Best Answer

  • ShayOhayonShayOhayon US ✭✭✭
    Accepted Answer

    OK. Figures this out.
    I can simply query "Intent" on the OnResume.
    The only issue is that, at that point, the ContextPage hasn't appeared yet. But it should be simply to store the tag information and check that in the "OnAppearing" callback.

Answers

  • JarvanJarvan Member, Xamarin Team Xamurai

    The intent filter requires a tech-list that specifies the tag technologies (or combinations of them) that the activity should be started for.

    [IntentFilter (new[]{NfcAdapter.ActionTechDiscovered})]
    [MetaData (NfcAdapter.ActionTechDiscovered, Resource="@xml/nfctech")]
    

    Then need to place a file "nfctech.xml" into the folder Resources/xml where you can define all the tag technologies that you want to listen to.

    <resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
        <tech-list>
            <tech>android.nfc.tech.NfcA</tech>
        </tech-list>
        ...
     </resources>
    

    Check the link:
    https://stackoverflow.com/questions/35587107/starting-application-on-nfc-tag-detection

  • ShayOhayonShayOhayon USMember ✭✭✭

    Hey

    Surprisingly this works...Kinda.
    So the app gets launched, but I don't get to the OnNewIntent callback after the app launches.
    If I scan again, then it does catch it, but if the app is closed, it will launch without that intent being called.
    Is there a solution for this?

  • ShayOhayonShayOhayon USMember ✭✭✭

    Ok. Here is more information.

    Looks like when the app is up & running, I'm actually getting TAG_DISCOVERED rather than TECH_DISCOVERED INTENT in the OnNewIntent callback (which is OK, I only need the serial number, not anything fancy).
    However, when the app is closed and a tag is presented, the app launched and I get the callback "OnResume" and not the OnNewIntent.

    How can I access this intent when I'm in the OnResume?

  • ShayOhayonShayOhayon USMember ✭✭✭
    Accepted Answer

    OK. Figures this out.
    I can simply query "Intent" on the OnResume.
    The only issue is that, at that point, the ContextPage hasn't appeared yet. But it should be simply to store the tag information and check that in the "OnAppearing" callback.

Sign In or Register to comment.