Exemplo n.º 1
0
        public override void OnReceive(Context context, Intent intent)
        {
            switch (intent.Action)
            {
            case BluetoothAdapter.ActionDiscoveryStarted:
                System.Diagnostics.Debug.WriteLine("DiscoveryStarted");
                break;

            case BluetoothAdapter.ActionDiscoveryFinished:
                System.Diagnostics.Debug.WriteLine("DiscoveryFinished");
                DiscoveryComplete?.Invoke(this, EventArgs.Empty);
                break;

            case BluetoothDevice.ActionFound:
                var device = (BluetoothDevice)intent.GetParcelableExtra(BluetoothDevice.ExtraDevice);
                if (device.Type != BluetoothDeviceType.Le)
                {
                    System.Diagnostics.Debug.WriteLine($"Found {device.Name} {device.Address} {device.BondState}");
                    DeviceFound?.Invoke(this, device);
                }
                break;

            case BluetoothDevice.ActionNameChanged:
                var device2 = (BluetoothDevice)intent.GetParcelableExtra(BluetoothDevice.ExtraDevice);
                System.Diagnostics.Debug.WriteLine($"Name Changed {device2.Name} {device2.Address}");
                break;

            case BluetoothDevice.ActionAclConnected:
                break;

            case BluetoothDevice.ActionAclDisconnected:
                break;
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Called when the discovery process is complete
        /// </summary>
        /// <param name="sender">Device watcher which did the discovery process</param>
        /// <param name="e">not used, always null</param>
        private void DeviceWatcher_EnumerationCompleted(DeviceWatcher sender, object e)
        {
            // Update discovery status
            _discovery_status = BleDiscoveryStatus.BDS_COMPLETE;
            _device_watcher.Stop();

            // Notify end of discovery
            DiscoveryComplete?.Invoke(this, BleDiscoveryStatus.BDS_COMPLETE);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Called when the discovery process has been stopped
        /// </summary>
        /// <param name="sender">Device watcher which did the discovery process</param>
        /// <param name="e">not used, always null</param>
        private void DeviceWatcher_Stopped(DeviceWatcher sender, object e)
        {
            // Check if the discovery process is not already complete
            if (_discovery_status != BleDiscoveryStatus.BDS_COMPLETE)
            {
                // Update discovery status
                _discovery_status = BleDiscoveryStatus.BDS_CANCELED;

                // Notify end of discovery
                DiscoveryComplete?.Invoke(this, BleDiscoveryStatus.BDS_CANCELED);
            }
        }
Exemplo n.º 4
0
 public void OnDiscoveryComplete(DiscoveryCompleteEventArgs e) => DiscoveryComplete?.Invoke(this, e);