/// <summary> /// /// </summary> public virtual void OnLeScan(BluetoothDevice device, int rssi, byte[] scanRecord) { // Get Address. string address = device.GetAddress(); if (string.IsNullOrEmpty(address)) { return; } Log.i("BluetoothScanner", address); // int i = deviceList.FindIndex((x) => (x.address == address)); if (i == -1) { deviceList.Add(new DeviceInfo { name = device.GetName(), address = address }); if (callback != null) { callback.OnDeviceListChanged(); } } else { address = device.GetName(); if (!string.IsNullOrEmpty(address)) { deviceList[i].name = address; } if (callback != null) { callback.OnDeviceListChanged(); } } }
public override void OnReceive(Context context, Intent intent) { String action = intent.Action; // When discovery finds a device if (BluetoothDevice.ACTION_FOUND.Equals(action)) { // Get the BluetoothDevice object from the Intent BluetoothDevice device = intent.GetParcelableExtra <BluetoothDevice>(BluetoothDevice.EXTRA_DEVICE); // If it's already paired, skip it, because it's been listed already if (device.GetBondState() != BluetoothDevice.BOND_BONDED) { activity.mNewDevicesArrayAdapter.Add(device.GetName() + "\n" + device.GetAddress()); } // When discovery is finished, change the Activity title } else if (BluetoothAdapter.ACTION_DISCOVERY_FINISHED.Equals(action)) { activity.SetProgressBarIndeterminateVisibility(false); activity.SetTitle(R.String.select_device); if (activity.mNewDevicesArrayAdapter.GetCount() == 0) { var noDevices = activity.Resources.GetText(R.String.none_found).ToString(); activity.mNewDevicesArrayAdapter.Add(noDevices); } } }