public override void OnReceive(Context context, Intent intent) { string action = intent.Action; if (BluetoothAdapter.ActionDiscoveryStarted == action) { this._BluetoothManager.IsDiscoverying = true; _BluetoothManager.OnDiscoveryStarted?.Invoke(_BluetoothManager); Application.Context.UnregisterReceiver(this); } if (BluetoothDevice.ActionFound == action) { BluetoothDevice device = intent.GetParcelableExtra(BluetoothDevice.ExtraDevice) as BluetoothDevice; BluetoothDeviceWrapper deviceWrapper = BluetoothDeviceWrapper.GetBluetoothDeviceFromDroidDevice(_BluetoothManager, device); _BluetoothManager.OnDevicesFound?.Invoke(_BluetoothManager, new RemoteX.Bluetooth.IBluetoothDevice[] { deviceWrapper }); } if (BluetoothAdapter.ActionDiscoveryFinished == action) { _BluetoothManager.IsDiscoverying = false; _BluetoothManager.OnDiscoveryFinished?.Invoke(_BluetoothManager); Application.Context.UnregisterReceiver(this); Application.Context.UnregisterReceiver(_BluetoothManager._DevicesFoundReceiver); } }
public void Setup(BluetoothDeviceWrapper bluetoothDeviceWrapper) { deviceWrapper = bluetoothDeviceWrapper; deviceName.text = deviceWrapper.Name; deviceAddress.text = deviceWrapper.Address; }
private void OnBondedDeviceDiscovered(BluetoothDeviceWrapper deviceWrapper) { var newEntry = Instantiate(bluetoothDeviceEntryPrefab, entryButtonsParent); newEntry.Setup(deviceWrapper); deviceEntries.Add(newEntry); }
public override void OnConnectionStateChange(BluetoothDevice droidDevice, [GeneratedEnum] ProfileState status, [GeneratedEnum] ProfileState newState) { base.OnConnectionStateChange(droidDevice, status, newState); var bluetoothDevice = BluetoothDeviceWrapper.GetBluetoothDeviceFromDroidDevice(GattServer.BluetoothManager, droidDevice); Log.Info("BLEAdver", bluetoothDevice + "OnConnectionStateChange Status:" + status + ", NewStatus:" + newState); bool alreadyConnected = false; foreach (var connectedDevice in GattServer._ConnectedDeviceList) { if (connectedDevice == bluetoothDevice) { alreadyConnected = true; break; } } if (newState == ProfileState.Connected) { if (!alreadyConnected) { GattServer._ConnectedDeviceList.Add(bluetoothDevice); GattServer.DeviceConnected?.Invoke(GattServer, bluetoothDevice); } } else if (newState == ProfileState.Disconnected) { if (alreadyConnected) { GattServer._ConnectedDeviceList.Remove(bluetoothDevice); GattServer.DeviceDisconnected?.Invoke(GattServer, bluetoothDevice); } } }
/// <summary> /// Will this update the BluetoothDevice locally ? /// Not yet! But I think it will be someday /// </summary> /// <param name="bluetoothManager"></param> /// <param name="droidDevice"></param> /// <returns></returns> public static BluetoothDeviceWrapper GetBluetoothDeviceFromDroidDevice(BluetoothManager bluetoothManager, Android.Bluetooth.BluetoothDevice droidDevice) { var existDevice = bluetoothManager._KnownBluetoothDevices.GetFromAddress(droidDevice.Address); if (existDevice == null) { existDevice = new BluetoothDeviceWrapper(droidDevice); bluetoothManager._KnownBluetoothDevices.Add(existDevice); } return(existDevice); }
public IBluetoothDevice GetBluetoothDevice(ulong macAddress) { byte[] addressBytesULong = BitConverter.GetBytes(macAddress); byte[] addressBytes = new byte[6]; for (int i = 0; i < addressBytes.Length; i++) { addressBytes[i] = addressBytesULong[5 - i]; } BluetoothDevice device = BluetoothAdapter.GetRemoteDevice(addressBytes); return(BluetoothDeviceWrapper.GetBluetoothDeviceFromDroidDevice(this, device)); }
public Task RunAcceptTask() { return(Task.Run(() => { while (true) { var bluetoothSocket = ServerSocket.Accept(); if (bluetoothSocket != null) { var rxDevice = BluetoothDeviceWrapper.GetBluetoothDeviceFromDroidDevice(BluetoothManager as BluetoothManager, bluetoothSocket.RemoteDevice); RfcommConnection rfcommConnection = new RfcommConnection(rxDevice, bluetoothSocket); _Connections.Add(rfcommConnection); OnConnectionReceived?.Invoke(this, rfcommConnection); } } })); }
public override void OnReceive(Context context, Intent intent) { string action = intent.Action; if (action == Android.Bluetooth.BluetoothAdapter.ActionDiscoveryStarted) { Application.Context.UnregisterReceiver(this); } if (action == Android.Bluetooth.BluetoothDevice.ActionFound) { Android.Bluetooth.BluetoothDevice droidDevice = intent.GetParcelableExtra(Android.Bluetooth.BluetoothDevice.ExtraDevice) as Android.Bluetooth.BluetoothDevice; var deviceWrapper = BluetoothDeviceWrapper.GetBluetoothDeviceFromDroidDevice(RfcommScanner.BluetoothManager, droidDevice); RfcommScanner.Added?.Invoke(RfcommScanner, deviceWrapper); } if (action == Android.Bluetooth.BluetoothAdapter.ActionDiscoveryFinished) { Application.Context.UnregisterReceiver(this); Application.Context.UnregisterReceiver(RfcommScanner.DevicesFoundReceiver); RfcommScanner.Status = BluetoothRfcommScannerState.EnumerationCompleted; RfcommScanner.EnumerationCompleted?.Invoke(RfcommScanner, null); } }
public Receiver(BluetoothDeviceWrapper deviceWrapper) { this._DeviceWrapper = deviceWrapper; }
private void OnBluetoothDeviceConnected(BluetoothDeviceWrapper deviceWrapper) { Debug.Log($"Bluetooth Device Connected: {deviceWrapper}"); SceneManager.LoadScene("MainScene"); }