public void Connect() { if (!IsConnected) { this.Gatt = PlatformDevice.ConnectGatt(Application.Context, true, this); IsConnected = true; } }
private IReadOnlyList <GattDeviceService> GetGattServices() { List <GattDeviceService> services = new List <GattDeviceService>(); if (_bluetoothGatt == null) { _gattCallback = new GattCallback(this); _bluetoothGatt = _device.ConnectGatt(Android.App.Application.Context, true, _gattCallback); _discoveryHandle.WaitOne(); } if (_bluetoothGatt.DiscoverServices()) { _discoveryHandle.WaitOne(); } foreach (BluetoothGattService service in _bluetoothGatt.Services) { services.Add(new GattDeviceService(this, service)); } return(services.AsReadOnly()); }
//TODO: this really should be async. in the xplat API, make sure to asyncify // Q: how to return in same context (requires a callback) public void ConnectToDevice (BluetoothDevice device) { // returns the BluetoothGatt, which is the API for BLE stuff // TERRIBLE API design on the part of google here. device.ConnectGatt (Android.App.Application.Context, true, this._gattCallback); }
internal BluetoothRemoteGATTServer(BluetoothDevice device, ABluetooth.BluetoothDevice bluetoothDevice) : this(device) { _gattCallback = new GattCallback(this); NativeGatt = bluetoothDevice.ConnectGatt(Android.App.Application.Context, false, _gattCallback); }
public void Connect(BluetoothDevice device, Action<ProfileState> onConnectionChanged) { _lastDevice = device; GattValue = device.ConnectGatt(Application.Context, false, GattClientObserver.Instance); _onConnection = onConnectionChanged; }