Example #1
0
 public DeviceObject(string id, bool isDefault, bool isEnabled, string name, IReadOnlyDictionary <string, object> properties, DeviceInformationKind Kind)
 {
     _id         = id;
     _isDefault  = isDefault;
     _isEnabled  = isEnabled;
     _name       = name;
     _properties = properties;
     _kind       = Kind;
 }
        private async void InterfaceIdTextBox_Loaded(object sender, RoutedEventArgs e)
        {
            DeviceInformationCollection deviceInfoCollection;

            // Pre-populate the text box with an interface id.
            deviceInfoCollection = await DeviceInformation.FindAllAsync(DeviceClass.AudioRender);
            if (deviceInfoCollection.Count > 0)
            {
                // When you want to "save" a DeviceInformation to get it back again later,
                // use both the DeviceInformation.Kind and the DeviceInformation.Id.
                interfaceIdTextBox.Text = deviceInfoCollection[0].Id;
                deviceInformationKind = deviceInfoCollection[0].Kind;
            }
        }
        private async void InterfaceIdTextBox_Loaded(object sender, RoutedEventArgs e)
        {
            DeviceInformationCollection deviceInfoCollection;

            // Pre-populate the text box with an interface id.
            deviceInfoCollection = await DeviceInformation.FindAllAsync(DeviceClass.AudioRender);

            if (deviceInfoCollection.Count > 0)
            {
                // When you want to "save" a DeviceInformation to get it back again later,
                // use both the DeviceInformation.Kind and the DeviceInformation.Id.
                interfaceIdTextBox.Text = deviceInfoCollection[0].Id;
                deviceInformationKind   = deviceInfoCollection[0].Kind;
            }
        }
Example #4
0
 public DeviceInfo()
 {
     Kind = DeviceInformationKind.Unknown;
     DeviceClassSelector = DeviceClass.All;
 }
Example #5
0
        private void StartWatcher()
        {
            DeviceInformationKind BluetoothDeviceKind = DeviceInformationKind.AssociationEndpoint;
            //string BluetoothDeviceFilter = "System.Devices.Aep.ProtocolId:=\"{e0cbf06c-cd8b-4647-bb8a-263b43f0f974}\"";
            string BluetoothDeviceFilter = "System.Devices.Aep.ProtocolId:=\"{bb7bb05e-5972-42b5-94fc-76eaa7084d49}\" OR System.Devices.Aep.ProtocolId:=\"{e0cbf06c-cd8b-4647-bb8a-263b43f0f974}\"";

            deviceWatcher = DeviceInformation.CreateWatcher(BluetoothDeviceFilter,
                                                            null, // don't request additional properties for this sample
                                                            BluetoothDeviceKind);


            m_BthDeviceCollection.Clear();

            handlerAdded = new TypedEventHandler <DeviceWatcher, DeviceInformation>(async(watcher, deviceInfo) =>
            {
                // Since we have the collection databound to a UI element, we need to update the collection on the UI thread.
                await this.Dispatcher.RunAsync(CoreDispatcherPriority.Low, () =>
                {
                    m_BthDeviceCollection.Add(new BthDevice(deviceInfo));
                });
            });

            deviceWatcher.Added += handlerAdded;
            handlerUpdated       = new TypedEventHandler <DeviceWatcher, DeviceInformationUpdate>(async(watcher, deviceInfoUpdate) =>
            {
                // Since we have the collection databound to a UI element, we need to update the collection on the UI thread.
                await this.Dispatcher.RunAsync(CoreDispatcherPriority.Low, () =>
                {
                    // Find the corresponding updated DeviceInformation in the collection and pass the update object
                    // to the Update method of the existing DeviceInformation. This automatically updates the object
                    // for us.
                    foreach (BthDevice device in m_BthDeviceCollection)
                    {
                        if (device.Id == deviceInfoUpdate.Id)
                        {
                            device.Update(deviceInfoUpdate);

                            break;
                        }
                    }
                });
            });

            deviceWatcher.Updated += handlerUpdated;

            handlerRemoved = new TypedEventHandler <DeviceWatcher, DeviceInformationUpdate>(async(watcher, deviceInfoUpdate) =>
            {
                // Since we have the collection databound to a UI element, we need to update the collection on the UI thread.
                await this.Dispatcher.RunAsync(CoreDispatcherPriority.Low, () =>
                {
                    // Find the corresponding DeviceInformation in the collection and remove it
                    foreach (BthDevice device in m_BthDeviceCollection)
                    {
                        if (device.Id == deviceInfoUpdate.Id)
                        {
                            m_BthDeviceCollection.Remove(device);
                            break;
                        }
                    }
                });
            });
            deviceWatcher.Removed += handlerRemoved;

            handlerEnumCompleted = new TypedEventHandler <DeviceWatcher, Object>(async(watcher, obj) =>
            {
                await this.Dispatcher.RunAsync(CoreDispatcherPriority.Low, () =>
                {
                });
            });
            deviceWatcher.EnumerationCompleted += handlerEnumCompleted;

            handlerStopped = new TypedEventHandler <DeviceWatcher, Object>(async(watcher, obj) =>
            {
                await this.Dispatcher.RunAsync(CoreDispatcherPriority.Low, () =>
                {
                });
            });
            deviceWatcher.Stopped += handlerStopped;
            deviceWatcher.Start();
        }