locked
NFC into cross-platform application RRS feed

  • Question

  • User358102 posted

    I want to work with NFC (read NFC-tags) into cross-platform application I found the example for NFC for Xamarin.Android on forum. Example works, and i try to do this for cross-platform, but met with obstacles

    (nfcAdapter = NfcAdapter.GetDefaultAdapter(this);) NfcAdapter in this case = NULL, but the phone has NFC (example works) I think the problem is because of the Content i can't get my content of ContentPage into Android for NfcAdapter, when I moved from ContentPage to the Android class, to access NFC classes on Android, i get content as class NFCWorker_Droid, which does not have access to the screen

    I assume that i need to migrate information about ContentPage through the interface, but I can not convert Xamarin.ContentPage to Android.Content

    With the help of the interface, I turn to the class that is in the android project Into ContentPage i call method of interface DependencyService.Get<INFCWorker>().EnableWriteMode(); and move to class into android project

    The code below shows the class code that is called in Android

    [assembly: Xamarin.Forms.Dependency(typeof(NFCWorker_Droid))]
    namespace TestNavigationPage2.Droid
    {
        public class NFCWorker_Droid : Activity,INFCWorker
        {
            public const string ViewApeMimeType = "application/vnd.xamarin.nfcxample";
            public static readonly string NfcAppRecord = "xamarin.nfxample";
            public static readonly string Tag = "NfcXample";
            private bool _inWriteMode;
            private NfcAdapter _nfcAdapter;
    
    public void EnableWriteMode()
            {
                _inWriteMode = true;
                // Get a reference to the default NFC adapter for this device. This adapter 
                // is how an Android application will interact with the actual hardware.
                _nfcAdapter = NfcAdapter.GetDefaultAdapter(this); 
                // Create an intent filter for when an NFC tag is discovered.  When
                // the NFC tag is discovered, Android will u
                var tagDetected = new IntentFilter(NfcAdapter.ActionTagDiscovered);
                var filters = new[] { tagDetected };
    
                // When an NFC tag is detected, Android will use the PendingIntent to come back to this activity.
                // The OnNewIntent method will invoked by Android.
                //var intent = new Intent(this, GetType());
                //var pendingIntent = PendingIntent.GetActivity(this, 0, intent, 0);
    
                if (_nfcAdapter == null)
                {
                    Page4.Instance.GlobalText = "NFC is not supported on this device.";
                }
                else
                {
                    DisplayMessage("NFC is here!");
                    //_nfcAdapter.EnableForegroundDispatch(this, pendingIntent, filters, null);
                }
            }
    }
    
    Tuesday, May 15, 2018 7:42 AM

All replies

  • User369767 posted

    @AndreyZhukov said: I want to work with NFC (read NFC-tags) into cross-platform application

    Hi @AndreyZhukov, ...is exactly what I need! Did you found a solution?

    Thank you!

    Friday, August 10, 2018 9:26 AM
  • User358102 posted

    @MaryLou said:

    @AndreyZhukov said: I want to work with NFC (read NFC-tags) into cross-platform application

    Hi @AndreyZhukov, ...is exactly what I need! Did you found a solution?

    Thank you!

    sorry, not found :(

    Sunday, September 23, 2018 3:14 PM
  • User155041 posted

    @AndreyZhukov said:

    @MaryLou said:

    @AndreyZhukov said: I want to work with NFC (read NFC-tags) into cross-platform application

    Hi @AndreyZhukov, ...is exactly what I need! Did you found a solution?

    Thank you!

    sorry, not found :(

    Have you tried this nuget

    https://github.com/poz1/NFCForms

    Wednesday, September 26, 2018 9:58 AM
  • User365818 posted

    Hi @Charwaka

    Is NFCForms nuget available for Xamarin.Forms.iOS?

    Thursday, July 11, 2019 1:41 PM
  • User228108 posted

    @Rajkumar_1992 there have been quite a few changes since your last message as IOS has finally allowed writing to NFC Tags now.

    I highly recommend the Plugin.NFC nuget package, it has a great sample therein as well.

    Also, I wrote an article on “Getting started with NFC in 5 minutes With Xamarin” that should explain the questions you have -www.bit.ly/2T9sBFy Let me know if you have any other questions

    Thursday, May 21, 2020 5:14 AM