Exemple #1
0
        public static async Task <bool> CheckHceSupport()
        {
            // Check if the SmartCardEmulator API exists on this currently running SKU of Windows
            if (!Windows.Foundation.Metadata.ApiInformation.IsTypePresent("Windows.Devices.SmartCards.SmartCardEmulator"))
            {
                LogMessage("This SKU of Windows does not support NFC card emulation, only phones/mobile devices support NFC card emulation", NotifyType.ErrorMessage);
                return(false);
            }

            // Check if any NFC emulation is supported on this device
            var sce = await SmartCardEmulator.GetDefaultAsync();

            if (sce == null)
            {
                LogMessage("NFC card emulation is not supported on this device, probably the device does not have NFC at all", NotifyType.ErrorMessage);
                return(false);
            }

            // Check if the NFC emulation support on this device includes HCE
            if (!sce.IsHostCardEmulationSupported())
            {
                LogMessage("This device's NFC does not support HCE-mode", NotifyType.ErrorMessage);
                return(false);
            }
            return(true);
        }
        private async void btnRegisterSamplePaymentCard_Click(object sender, RoutedEventArgs e)
        {
            // Clear the messages
            rootPage.NotifyUser(String.Empty, NotifyType.StatusMessage, true);

            // First check if the device supports NFC/HCE at all
            if (!(await NfcUtils.CheckHceSupport()))
            {
                // HCE not supported
                return;
            }

            // Next check if NFC card emualtion is turned on in the settings control panel
            if ((await SmartCardEmulator.GetDefaultAsync()).EnablementPolicy == SmartCardEmulatorEnablementPolicy.Never)
            {
                ShowDialog("Your NFC tap+pay setting is turned off, you will be taken to the NFC control panel to turn it on");

                // This URI will navigate the user to the NFC tap+pay control panel
                NfcUtils.LaunchNfcPaymentsSettingsPage();
                return;
            }

            this.Frame.Navigate(typeof(SetCardDataScenario));
        }