internal async void OnBleDeviceUpdated_InBackground(string status, string name, string btId) { // string bleId = BluetoothDevices.ConvertDeviceIdType(btId, AddressType.BLE); DeviceInformation btDeviceInfo = await DeviceInformation.CreateFromIdAsync(btId); if ("added".Equals(status)) { if (btDeviceInfo.Pairing.IsPaired) { /* * Earbuds targetEarbuds = GetNaerByEarbirds(bleId); * if (targetEarbuds != null && !targetEarbuds.BleConnected) * { * ToastHelper.ShowPairedBleDeviceAddedToast(name, btId); * } else * { * ToastHelper.ShowToast($"Already Paired, Your Device Found.\nID:{btId}"); * } */ } else if (btDeviceInfo.Pairing.CanPair) { ToastHelper.ShowNewBleDeviceToast(name, btId); } else { // ToastHelper.ShowToast($"New Device Found, but Cannot Pair.\nID:{btId}"); } } /* * else if ("removed".Equals(status)) * { * if (!btDeviceInfo.Pairing.IsPaired) * { * ToastHelper.ShowToast($"Your Devie (NOT Paired) moved away.\nID:{btId}"); * } * else * { * ToastHelper.ShowBleDeviceRemovedToast(name, btId); * } * } */ }
private async void OnRequestReceived(AppServiceConnection sender, AppServiceRequestReceivedEventArgs args) { if (args.Request.Message.ContainsKey("opcode")) { object value = null; string opcode = null; args.Request.Message.TryGetValue("opcode", out value); opcode = value as string; if ("ble_device".Equals(opcode)) { string status = null; string name = null; string id = null; args.Request.Message.TryGetValue("status", out value); status = value as string; args.Request.Message.TryGetValue("name", out value); name = value as string; args.Request.Message.TryGetValue("id", out value); id = value as string; OnBleDeviceUpdated(status, name, id); } if ("a2dp".Equals(opcode)) { string command = null; string id = null; args.Request.Message.TryGetValue("command", out value); command = value as string; args.Request.Message.TryGetValue("id", out value); id = value as string; App.sDeviceManager.OnA2dpCommandReceived(command, id); } else if ("log".Equals(opcode)) { string level = null; string message = null; args.Request.Message.TryGetValue("level", out value); level = value as string; args.Request.Message.TryGetValue("message", out value); message = value as string; Log.Print(level, message); } } if (args.Request.Message.ContainsKey("content")) { args.Request.Message.TryGetValue("content", out object message); if (App.IsForeground) { await Windows.ApplicationModel.Core.CoreApplication.MainView.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, new DispatchedHandler(async() => { MessageDialog dialog = new MessageDialog(message.ToString()); await dialog.ShowAsync(); })); } else { ToastHelper.ShowToast(message.ToString()); } } if (args.Request.Message.ContainsKey("exit")) { App.Current.Exit(); } }