private static Intent PairDevice(NFCDevice nfcDevice, Intent intent) { BluetoothDevice device = _BluetoothAdapter.GetRemoteDevice(nfcDevice.MacAddress); if (device != null) { OnDevicePaired(device, device.CreateBond(), intent, EventArgs.Empty); } else { intent.PutExtra("ErrorMessage", "Failed to communicate with device"); } return(intent); }
private static Intent ProcessNfcScan(Intent intent) { IParcelable[] scannedTags = intent.GetParcelableArrayExtra(NfcAdapter.ExtraNdefMessages); if (scannedTags != null && scannedTags.Length > 0) { try { NdefMessage msg = (NdefMessage)scannedTags[0]; byte[] payloadBytes = msg.GetRecords()[0].GetPayload(); String payload = String.Empty; foreach (byte b in payloadBytes) { payload += Convert.ToChar(b); } NFCDevice nfcDevice = new NFCDevice { FriendlyName = GetDeviceFriendlyName(payload), MacAddress = GetDeviceMacAddress(payloadBytes), }; bool alreadyPaired = false; for (int i = 0; i < _deviceList.Count; i++) { if ((_deviceList[i].Name == nfcDevice.FriendlyName) && (_deviceList[i].Address == nfcDevice.MacAddress)) { alreadyPaired = true; break; } } if (!alreadyPaired) { intent = PairDevice(nfcDevice, intent); } else { intent.PutExtra("ErrorMessage", "Device Already Paired"); } } catch (Exception ex) { } intent.RemoveExtra(NfcAdapter.ExtraNdefMessages); } return(intent); }