Forum Xamarin.Android
We are excited to announce that the Xamarin Forums are moving to the new Microsoft Q&A experience. Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

We encourage you to head over to Microsoft Q&A for .NET for posting new questions and get involved today.

NfcAdapter reopening the app??

RicardoSRicardoS ESMember ✭✭✭

Hello and salutations,

I'm working on an app with a card-reading interface, that "supposedly" adds a user to a list of people (then sent to a database) by a nfcadapter. Here is the (still a work-in-progress) code:

`
protected string TagUid;

    protected override void OnCreate(Bundle savedInstanceState) {
        base.OnCreate(savedInstanceState);
        SetContentView(Resource.Layout.Main);
    }

    protected override void OnResume() {
        base.OnResume();
        if (NfcAdapter.ActionTechDiscovered.Equals(Intent.Action)) {
            Tag tag = Intent.GetParcelableExtra(NfcAdapter.ExtraTag) as Tag;
            if (tag != null) {
                TagUid = ByteArrayToString(tag.GetId());
                Log.Info("Tag", string.Format("Card UID is {0}", TagUid));
                HandleNfcCardPresented(this, TagUid);
            }
        }
    }

    //Convert the byte array of the NfcCard Uid to string
    static string ByteArrayToString(byte[] bArray) {
        StringBuilder hex = new StringBuilder(bArray.Length * 2);
        foreach (byte b in bArray) { hex.AppendFormat("{0:x2}", b); }
        return hex.ToString().ToUpper();
    }

    //Do something with the card UID
    static void HandleNfcCardPresented(Context context, string uid) {
        Toast.MakeText(context, string.Format("Card UID is {0}", uid), ToastLength.Short).Show();

    }
}

`

The code has to read the nfc card and show a toast with its id, but once is installed in a tablet, the card starts the app by its own.
I want the app to run normally. Please, I need your help.

Thanks in advance.

Sign In or Register to comment.