/// <summary> /// Returns first device supports smart card reader mode /// </summary> /// <returns>None</returns> public static async Task <DeviceInformation> GetFirstSmartCardReaderInfo(SmartCardReaderKind readerKind = SmartCardReaderKind.Any) { // Check if the SmartCardConnection API exists on this currently running SKU of Windows if (!Windows.Foundation.Metadata.ApiInformation.IsTypePresent("Windows.Devices.SmartCards.SmartCardConnection")) { // This SKU of Windows does not support NFC card reading, // only desktop and phones/mobile devices support NFC card reading return(null); } // Device selector string is from SmartCardReader.GetDeviceSelector(SmartCardReaderKind.Nfc) // except that we remove the conditional about the interface being enabled, // since we want to get the device object regardless of whether the user turned it off in the CPL string query = "System.Devices.InterfaceClassGuid:=\"{DEEBE6AD-9E01-47E2-A3B2-A66AA2C036C9}\""; if (readerKind != SmartCardReaderKind.Any) { query += " AND System.Devices.SmartCards.ReaderKind:=" + (int)readerKind; } DeviceInformationCollection devices = await DeviceInformation.FindAllAsync(query); int numOfDevices = devices.Count; // There is a bug on some devices that were updated to WP8.1 where an NFC SmartCardReader is // enumerated despite that the device does not support it. As a workaround, we can do an additonal check // to ensure the device truly does support it. var workaroundDetect = await DeviceInformation.FindAllAsync("System.Devices.InterfaceClassGuid:=\"{50DD5230-BA8A-11D1-BF5D-0000F805F530}\""); if (workaroundDetect.Count == 0 || devices.Count == 0) { // Not supported return(null); } // Smart card reader supported, but may be disabled return((from d in devices where d.IsEnabled orderby d.IsDefault descending select d).FirstOrDefault()); } // GetFirstSmartCardReaderInfo
/// <summary> /// Checks whether the device supports smart card reader mode /// </summary> /// <returns>None</returns> public static async Task <SmartCardReaderDetectionResult> GetFirstSmartCardReaderInfo( SmartCardReaderKind readerKind = SmartCardReaderKind.Any) { if (!Windows.Foundation.Metadata.ApiInformation.IsTypePresent("Windows.Devices.SmartCards.SmartCardConnection")) { return(null); } // NXP PN547 NFC I2C Transport Driver string query = "System.Devices.InterfaceClassGuid:=\"{DEEBE6AD-9E01-47E2-A3B2-A66AA2C036C9}\""; if (readerKind != SmartCardReaderKind.Any) { query += " AND System.Devices.SmartCards.ReaderKind:=" + (int)readerKind; } DeviceInformationCollection devices = await DeviceInformation.FindAllAsync(query); // SmardCardReader var disableCheck = await DeviceInformation.FindAllAsync("System.Devices.InterfaceClassGuid:=\"{50DD5230-BA8A-11D1-BF5D-0000F805F530}\""); if (devices.Count == 0 || disableCheck.Count == 0) { // Not supported return(null); } // Smart card reader supported, but may be disabled DeviceInformation info = (from d in devices where d.IsEnabled orderby d.IsDefault descending select d).FirstOrDefault(); return(new SmartCardReaderDetectionResult() { Id = info.Id, DeviceInfo = info, IsEnabled = disableCheck[0].IsEnabled, }); }
/// <summary> /// Checks whether the device supports smart card reader mode /// </summary> /// <returns>None</returns> public static async Task<DeviceInformation> GetFirstSmartCardReaderInfo(SmartCardReaderKind? readerKind = SmartCardReaderKind.Nfc) { // Check if the SmartCardConnection API exists on this currently running SKU of Windows if (!Windows.Foundation.Metadata.ApiInformation.IsTypePresent("Windows.Devices.SmartCards.SmartCardConnection")) { // This SKU of Windows does not support NFC card reading, only desktop and phones/mobile devices support NFC card reading return null; } // Device selector string is from SmartCardReader.GetDeviceSelector(SmartCardReaderKind.Nfc) except that we remove the conditional // about the interface being enabled, since we want to get the device object regardless of whether the user turned it off in the CPL DeviceInformationCollection devices = await DeviceInformation.FindAllAsync("System.Devices.InterfaceClassGuid:=\"{DEEBE6AD-9E01-47E2-A3B2-A66AA2C036C9}\"" + (readerKind == null ? string.Empty : " AND System.Devices.SmartCards.ReaderKind:=" + (int)readerKind)); // There is a bug on some devices that were updated to WP8.1 where an NFC SmartCardReader is // enumerated despite that the device does not support it. As a workaround, we can do an additonal check // to ensure the device truly does support it. var workaroundDetect = await DeviceInformation.FindAllAsync("System.Devices.InterfaceClassGuid:=\"{50DD5230-BA8A-11D1-BF5D-0000F805F530}\""); if (workaroundDetect.Count == 0 || devices.Count == 0) { // Not supported return null; } // Smart card reader supported, but may be disabled return (from d in devices where d.IsEnabled orderby d.IsDefault descending select d).FirstOrDefault(); }
/// <summary> /// Checks whether the device supports smart card reader mode /// </summary> /// <returns>None</returns> public static async Task <DeviceInformation> GetFirstSmartCardReaderInfo(SmartCardReaderKind readerKind = SmartCardReaderKind.Any) { // Check if the SmartCardConnection API exists on this currently running SKU of Windows if (!Windows.Foundation.Metadata.ApiInformation.IsTypePresent("Windows.Devices.SmartCards.SmartCardConnection")) { // This SKU of Windows does not support NFC card reading, only desktop and phones/mobile devices support NFC card reading return(null); } // Device selector string is from SmartCardReader.GetDeviceSelector(SmartCardReaderKind.Nfc) except that we remove the conditional // about the interface being enabled, since we want to get the device object regardless of whether the user turned it off in the CPL string query = "System.Devices.InterfaceClassGuid:=\"{DEEBE6AD-9E01-47E2-A3B2-A66AA2C036C9}\""; //if (readerKind != SmartCardReaderKind.Any) //{ // query += " AND System.Devices.SmartCards.ReaderKind:=" + (int)readerKind; //} DeviceInformationCollection devices = await DeviceInformation.FindAllAsync(query); if (devices.Count == 0) { devices = await DeviceInformation.FindAllAsync("System.Devices.InterfaceClassGuid:=\"{9a2fc585-7316-46f1-9577-500920304f9d}\""); } // There is a bug on some devices that were updated to WP8.1 where an NFC SmartCardReader is // enumerated despite that the device does not support it. As a workaround, we can do an additonal check // to ensure the device truly does support it. var workaroundDetect = await DeviceInformation.FindAllAsync("System.Devices.InterfaceClassGuid:=\"{50DD5230-BA8A-11D1-BF5D-0000F805F530}\""); if (workaroundDetect.Count == 0 || devices.Count == 0) { // Not supported if (readerKind == SmartCardReaderKind.Any) { query = DeviceInformation.GetAqsFilterFromDeviceClass(DeviceClass.ImageScanner); workaroundDetect = await DeviceInformation.FindAllAsync(query); if (workaroundDetect.Count == 0) { workaroundDetect = await DeviceInformation.FindAllAsync(); if (workaroundDetect.Count == 0) { return(null); } foreach (var item in workaroundDetect) { if (item.Name.ToLower().Contains("NPX".ToLower()) || item.Name.ToLower().Contains("Proximity".ToLower()) || item.Name.ToLower().Contains("Near".ToLower())) { return((from d in workaroundDetect where d.IsEnabled orderby d.IsDefault descending select d).FirstOrDefault()); } } } ; } } else if (devices.Count == 0 && workaroundDetect.Count > 0) { devices = workaroundDetect; } // Smart card reader supported, but may be disabled return((from d in devices where d.IsEnabled orderby d.IsDefault descending select d).FirstOrDefault()); }