Exemplo n.º 1
0
        //Starts the service. Returns true if started sucessfully and false otherwise.
        public async Task <bool> InitializeServiceAsync(DeviceInformation device)
        {
            try
            {
                _deviceContainerId = "{" + device.Properties[ContainerIDProperty] + "}";

                try
                {
                    _service = await GattDeviceService.FromIdAsync(device.Id);
                }
                catch (Exception e)
                {
                    if (e.Message.Contains("Bluetooth"))
                    {
                        BluetoothNotEnabled?.Invoke();
                    }
                    else
                    {
                        LoggerWrapper.Instance.WriteToLogFile(e);
                        LoggerWrapper.Instance.WriteToConsole("Can't initialize bluetooth service: " + e.Message.ToString());
                    }

                    return(false);
                }

                if (_service != null)
                {
                    IsServiceInitialized = true;
                    await ConfigureServiceForNotificationsAsync();

                    return(true);
                }
                else
                {
                    LoggerWrapper.Instance.WriteToConsole("Access to the device is denied, because the application was not granted access, or the device is currently in use by another application.");
                    return(false);
                }
            }
            catch (Exception e)
            {
                return(false);
            }
        }
Exemplo n.º 2
0
 private void OnBluetoothNotEnabled()
 {
     BluetoothNotEnabled?.Invoke();
 }