public static async Task <string> RegisterBackgroundTask(Guid uuid, string serviceName, string serviceDescriptor) { System.Diagnostics.Debug.WriteLine("RegisterBackgroundTask"); try { // Applications registering for background trigger must request for permission. BackgroundAccessStatus backgroundAccessStatus = await BackgroundExecutionManager.RequestAccessAsync(); BackgroundTaskBuilder backgroundTaskBuilder = new BackgroundTaskBuilder(); backgroundTaskBuilder.Name = BackgroundTaskName; backgroundTaskBuilder.TaskEntryPoint = BackgroundTaskEntryPoint; RfcommConnectionTrigger trigger = new RfcommConnectionTrigger(); trigger.InboundConnection.LocalServiceId = RfcommServiceId.FromUuid(uuid); // TODO: helper function to create sdpRecordBlob trigger.InboundConnection.SdpRecord = getsdpRecordBlob(serviceName, serviceDescriptor); //backgroundTaskBuilder.SetTrigger(new SystemTrigger(SystemTriggerType.TimeZoneChange, false)); backgroundTaskBuilder.SetTrigger(trigger); BackgroundTaskRegistration backgroundTaskRegistration = backgroundTaskBuilder.Register(); } catch (Exception e) { System.Diagnostics.Debug.WriteLine("ERROR: Accessing your device failed." + Environment.NewLine + e.Message); return("ERROR: Accessing your device failed." + Environment.NewLine + e.Message); } return(null); }
public Scenario3_BgChatServer() { this.InitializeComponent(); trigger = new RfcommConnectionTrigger(); trigger.InboundConnection.LocalServiceId = RfcommServiceId.FromUuid(Constants.RfcommChatServiceUuid); // TODO: helper function to create sdpRecordBlob trigger.InboundConnection.SdpRecord = sdpRecordBlob.AsBuffer(); }
public Scenario3_BgChatServer() { this.InitializeComponent(); trigger = new RfcommConnectionTrigger(); // Local service Id is the only mandatory field that should be used to filter a known service UUID. trigger.InboundConnection.LocalServiceId = RfcommServiceId.FromUuid(Constants.RfcommChatServiceUuid); // The SDP record is nice in order to populate optional name and description fields trigger.InboundConnection.SdpRecord = sdpRecordBlob.AsBuffer(); }
async void MainPage_Loaded(object sender, RoutedEventArgs e) { var promise = await BackgroundExecutionManager.RequestAccessAsync(); if (promise == BackgroundAccessStatus.Denied) { var warning = new MessageDialog("Background execution is disabled. Please re-enable to allow this sample to receive messages", "Background Tasks"); await warning.ShowAsync(); } else { bool taskRegistered = false; foreach (var task in BackgroundTaskRegistration.AllTasks) { if (task.Value.Name == TaskName) { taskRegistered = true; break; } } if (!taskRegistered) { var trigger = new RfcommConnectionTrigger(); trigger.InboundConnection.LocalServiceId = RfcommServiceId.FromUuid(App.ChatServiceID); // add a default service name (not localised) //SdpDataElement rec = new SdpDataElement(new List<SdpDataElement> { new SdpDataElement((ushort)0x100), new SdpDataElement("BluetoothChat Sample") }); trigger.AllowMultipleConnections = true; var builder = new BackgroundTaskBuilder(); builder.Name = "BluetoothChat"; builder.TaskEntryPoint = "BluetoothChat.BackgroundTask.BluetoothChatBackgroundTask"; builder.SetTrigger(trigger); try { var reg = builder.Register(); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex); } } } }
public MainPage() { InitializeComponent(); InitializeRadios(); InitializeNotificationListener(); OpenNotificationAppsFile(); _trigger = new RfcommConnectionTrigger(); // Local service Id is the only mandatory field that should be used to filter a known service UUID. if (_trigger.InboundConnection == null) { return; } _trigger.InboundConnection.LocalServiceId = RfcommServiceId.FromUuid(Constants.RfcommChatServiceUuid); // The SDP record is nice in order to populate optional name and description fields _trigger.InboundConnection.SdpRecord = _sdpRecordBlob.AsBuffer(); InitializeSongTitleTimer(); }
public static async Task<string> RegisterBackgroundTask(Guid uuid, string serviceName, string serviceDescriptor) { System.Diagnostics.Debug.WriteLine("RegisterBackgroundTask"); try { // Applications registering for background trigger must request for permission. BackgroundAccessStatus backgroundAccessStatus = await BackgroundExecutionManager.RequestAccessAsync(); BackgroundTaskBuilder backgroundTaskBuilder = new BackgroundTaskBuilder(); backgroundTaskBuilder.Name = BackgroundTaskName; backgroundTaskBuilder.TaskEntryPoint = BackgroundTaskEntryPoint; RfcommConnectionTrigger trigger = new RfcommConnectionTrigger(); trigger.InboundConnection.LocalServiceId = RfcommServiceId.FromUuid(uuid); // TODO: helper function to create sdpRecordBlob trigger.InboundConnection.SdpRecord = getsdpRecordBlob(serviceName, serviceDescriptor); //backgroundTaskBuilder.SetTrigger(new SystemTrigger(SystemTriggerType.TimeZoneChange, false)); backgroundTaskBuilder.SetTrigger(trigger); BackgroundTaskRegistration backgroundTaskRegistration = backgroundTaskBuilder.Register(); } catch (Exception e) { System.Diagnostics.Debug.WriteLine("ERROR: Accessing your device failed." + Environment.NewLine + e.Message); return "ERROR: Accessing your device failed." + Environment.NewLine + e.Message; } return null; }