private async void App_InboundPairingRequested(object sender, InboundPairingEventArgs inboundArgs) { // Ignore the inbound if pairing is already in progress if (inProgressPairButton == null) { await MainPage.Current.UIThreadDispatcher.RunAsync(CoreDispatcherPriority.Normal, async() => { // Make sure the Bluetooth grid is showing await SwitchToSelectedSettingsAsync("BluetoothListViewItem"); // Restore the ceremonies we registered with var localSettings = Windows.Storage.ApplicationData.Current.LocalSettings; Object supportedPairingKinds = localSettings.Values["supportedPairingKinds"]; int iSelectedCeremonies = (int)DevicePairingKinds.ConfirmOnly; if (supportedPairingKinds != null) { iSelectedCeremonies = (int)supportedPairingKinds; } SetSelectedCeremonies(iSelectedCeremonies); // Clear any previous devices bluetoothDeviceObservableCollection.Clear(); // Add latest BluetoothDeviceInformationDisplay deviceInfoDisp = new BluetoothDeviceInformationDisplay(inboundArgs.DeviceInfo); bluetoothDeviceObservableCollection.Add(deviceInfoDisp); // Display a message about the inbound request string formatString = BluetoothDeviceInformationDisplay.GetResourceString("BluetoothInboundPairingRequestFormat"); string confirmationMessage = string.Format(formatString, deviceInfoDisp.Name, deviceInfoDisp.Id); DisplayMessagePanelAsync(confirmationMessage, MessageType.InformationalMessage); }); } }
protected override void OnActivated(IActivatedEventArgs args) { // Spot if we are being activated due to inbound pairing request if (null != args && args.Kind == ActivationKind.DevicePairing) { // Ensure the main app loads first OnLaunched(null); // Get the arguments, which give information about the device which wants to pair with this app var devicePairingArgs = (DevicePairingActivatedEventArgs)args; var di = devicePairingArgs.DeviceInformation; // Automatically switch to Bluetooth Settings page NavigationUtils.NavigateToScreen(typeof(Settings), "BluetoothListViewItem"); int bluetoothSettingsIndex = 2; Frame rootFrame = Window.Current.Content as Frame; ListView settingsListView = null; settingsListView = (rootFrame.Content as FrameworkElement).FindName("SettingsChoice") as ListView; settingsListView.Focus(FocusState.Programmatic); bluetoothSettingsIndex = Math.Min(bluetoothSettingsIndex, settingsListView.Items.Count - 1); settingsListView.SelectedIndex = bluetoothSettingsIndex; // Appropriate Bluetooth Listview grid content is forced by App_InboundPairingRequested call to SwitchToSelectedSettings // Fire the event letting subscribers know there's a new inbound request. // In this case Scenario should be subscribed. if (InboundPairingRequested != null) { InboundPairingEventArgs inboundEventArgs = new InboundPairingEventArgs(di); InboundPairingRequested(this, inboundEventArgs); } } }
protected override void OnActivated(IActivatedEventArgs args) { // Spot if we are being activated due to inbound pairing request if (args.Kind == ActivationKind.DevicePairing) { // Ensure the main app loads first OnLaunched(null); // Get the arguments, which give information about the device which wants to pair with this app var devicePairingArgs = (DevicePairingActivatedEventArgs)args; var di = devicePairingArgs.DeviceInformation; // Automatically switch to Bluetooth Settings page NavigationUtils.NavigateToScreen(typeof(Settings)); int bluetoothSettingsIndex = 2; Frame rootFrame = Window.Current.Content as Frame; ListView settingsListView = null; settingsListView = (rootFrame.Content as FrameworkElement).FindName("SettingsChoice") as ListView; settingsListView.Focus(FocusState.Programmatic); bluetoothSettingsIndex = Math.Min(bluetoothSettingsIndex, settingsListView.Items.Count - 1); settingsListView.SelectedIndex = bluetoothSettingsIndex; // Appropriate Bluetooth Listview grid content is forced by App_InboundPairingRequested call to SwitchToSelectedSettings // Fire the event letting subscribers know there's a new inbound request. // In this case Scenario should be subscribed. if (InboundPairingRequested != null) { InboundPairingEventArgs inboundEventArgs = new InboundPairingEventArgs(di); InboundPairingRequested(this, inboundEventArgs); } } }
private async void App_InboundPairingRequested(object sender, InboundPairingEventArgs inboundArgs) { // Ignore the inbound if pairing is already in progress if (inProgressPairButton == null) { await MainPage.Current.UIThreadDispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { // Make sure the Bluetooth grid is showing SwitchToSelectedSettings("BluetoothListViewItem"); // Restore the ceremonies we registered with var localSettings = Windows.Storage.ApplicationData.Current.LocalSettings; Object supportedPairingKinds = localSettings.Values["supportedPairingKinds"]; int iSelectedCeremonies = (int)DevicePairingKinds.ConfirmOnly; if (supportedPairingKinds != null) { iSelectedCeremonies = (int)supportedPairingKinds; } SetSelectedCeremonies(iSelectedCeremonies); // Clear any previous devices bluetoothDeviceObservableCollection.Clear(); // Add latest BluetoothDeviceInformationDisplay deviceInfoDisp = new BluetoothDeviceInformationDisplay(inboundArgs.DeviceInfo); bluetoothDeviceObservableCollection.Add(deviceInfoDisp); // Display a message about the inbound request string formatString = BluetoothDeviceInformationDisplay.GetResourceString("BluetoothInboundPairingRequestFormat"); string confirmationMessage = string.Format(formatString, deviceInfoDisp.Name, deviceInfoDisp.Id); DisplayMessagePanel(confirmationMessage, MessageType.InformationalMessage); }); } }