public Adapter () { var appContext = Application.Context; // get a reference to the bluetooth system service this._manager = (BluetoothManager) appContext.GetSystemService("bluetooth"); this._adapter = this._manager.Adapter; if (Build.VERSION.SdkInt >= BuildVersionCodes.Lollipop) { this.setLollipopProperty(); } this._gattCallback = new GattCallback (this); this._gattCallback.DeviceConnected += (object sender, DeviceConnectionEventArgs e) => { Console.WriteLine("Device Connected: "+ e.Device.Name); this._connectedDevices.Add ( e.Device); this.DeviceConnected (this, e); }; this._gattCallback.DeviceDisconnected += (object sender, DeviceConnectionEventArgs e) => { // TODO: remove the disconnected device from the _connectedDevices list // i don't think this will actually work, because i'm created a new underlying device here. if(this._connectedDevices.Contains(e.Device)) { this._connectedDevices.Remove(e.Device); } this.DeviceDisconnected (this, e); }; }
public BluetoothConnectionHandler(BluetoothManager manager) { _manager = manager; var gattClientObserver = GattClientObserver.Instance; gattClientObserver.ConnectionStateChanged += OnConnectionStateChanged; gattClientObserver.ServicesDiscovered += OnServicesDiscovered; }
public Adapter() { ScanTimeout = 10000; DeviceOperationRegistry = new Dictionary<string, IDevice>(); ConnectedDeviceRegistry = new Dictionary<string, IDevice>(); var appContext = Android.App.Application.Context; // get a reference to the bluetooth system service this._manager = (BluetoothManager)appContext.GetSystemService(Context.BluetoothService); this._adapter = this._manager.Adapter; var bondStatusBroadcastReceiver = new BondStatusBroadcastReceiver(); Application.Context.RegisterReceiver(bondStatusBroadcastReceiver, new IntentFilter(BluetoothDevice.ActionBondStateChanged)); //forward events from broadcast receiver bondStatusBroadcastReceiver.BondStateChanged += (s, args) => { this.DeviceBondStateChanged(this, args); }; if (Build.VERSION.SdkInt >= BuildVersionCodes.Lollipop) { _api21ScanCallback = new Api21BleScanCallback(this); } }
public Adapter(Context appContext) { ScanTimeout = TimeSpan.FromSeconds(10); // default timeout is 10 seconds _appContext = appContext; // get a reference to the bluetooth system service this._manager = appContext.GetSystemService("bluetooth").JavaCast<BluetoothManager>(); this._adapter = this._manager.Adapter; this._gattCallback = new GattCallback(this); this._gattCallback.DeviceConnected += (object sender, DeviceConnectionEventArgs e) => { if (ConnectedDevices.Find((BluetoothDevice)e.Device.NativeDevice) == null) { _connectedDevices.Add(e.Device); this.DeviceConnected(this, e); } }; this._gattCallback.DeviceDisconnected += (object sender, DeviceConnectionEventArgs e) => { var device = ConnectedDevices.Find((BluetoothDevice)e.Device.NativeDevice); if (device != null) { _connectedDevices.Remove(device); this.DeviceDisconnected(this, e); } }; }
protected BluetoothLEManager () { var appContext = Android.App.Application.Context; // get a reference to the bluetooth system service this._manager = (BluetoothManager) appContext.GetSystemService("bluetooth"); this._adapter = this._manager.Adapter; this._gattCallback = new GattCallback (this); }
public BluetoothManager() { _IsDiscoverying = false; BluetoothAdapter = BluetoothAdapter.DefaultAdapter; RfcommScanner = new RfcommScanner(this); _KnownBluetoothDevices = new List <BluetoothDeviceWrapper>(); DroidBluetoothManager = Application.Context.GetSystemService(Context.BluetoothService) as Android.Bluetooth.BluetoothManager; ServiceProviderList = new List <IRfcommServiceProvider>(); }
public DroidToothReactive () { var appContext = Android.App.Application.Context; // get a reference to the bluetooth system service this.Manager = (BluetoothManager) appContext.GetSystemService("bluetooth"); this.Adapter = this.Manager.Adapter; BroodSubject = new Subject<BroodtoothDevice> (); }
public BluetoothManager() { _IsDiscoverying = false; BluetoothAdapter = BluetoothAdapter.DefaultAdapter; _DiscoveryStartedReceiver = new Receiver(this); _DevicesFoundReceiver = new Receiver(this); _DiscoveryFinishedReceiver = new Receiver(this); _BluetoothConnections = new List <BluetoothClientConnection>(); _KnownBluetoothDevices = new List <BluetoothDeviceWrapper>(); DroidBluetoothManager = Application.Context.GetSystemService(Context.BluetoothService) as Android.Bluetooth.BluetoothManager; }
protected override void InitializeNative() { var ctx = Application.Context; if (!ctx.PackageManager.HasSystemFeature(PackageManager.FeatureBluetoothLe)) return; var statusChangeReceiver = new BluetoothStatusBroadcastReceiver(UpdateState); ctx.RegisterReceiver(statusChangeReceiver, new IntentFilter(BluetoothAdapter.ActionStateChanged)); _bluetoothManager = (BluetoothManager)ctx.GetSystemService(Context.BluetoothService); }
/// <summary> /// Initializes a new instance of the <see cref="BluetoothLE.Droid.Adapter"/> class. /// </summary> public Adapter() { var appContext = Android.App.Application.Context; _manager = (BluetoothManager)appContext.GetSystemService("bluetooth"); _adapter = _manager.Adapter; _callback = new GattCallback(); _callback.DeviceConnected += BluetoothGatt_DeviceConnected; _callback.DeviceDisconnected += BluetoothGatt_DeviceDisconnected; ConnectedDevices = new List<IDevice>(); }
public Adapter () { var appContext = Android.App.Application.Context; // get a reference to the bluetooth system service this._manager = (BluetoothManager) appContext.GetSystemService("bluetooth"); this._adapter = this._manager.Adapter; this._gattCallback = new GattCallback (this); this._gattCallback.DeviceConnected += (object sender, DeviceConnectionEventArgs e) => { this._connectedDevices.Add ( e.Device); this.DeviceConnected (this, e); }; this._gattCallback.DeviceDisconnected += (object sender, DeviceConnectionEventArgs e) => { // TODO: remove the disconnected device from the _connectedDevices list // i don't think this will actually work, because i'm created a new underlying device here. //if(this._connectedDevices.Contains( this.DeviceDisconnected (this, e); }; }
public BleServer(Context ctx) { _bluetoothManager = (BluetoothManager)ctx.GetSystemService(Context.BluetoothService); _bluetoothAdapter = _bluetoothManager.Adapter; _bluettothServerCallback = new BleGattServerCallback(); _bluetoothServer = _bluetoothManager.OpenGattServer(ctx, _bluettothServerCallback); var service = new BluetoothGattService(UUID.FromString("ffe0ecd2-3d16-4f8d-90de-e89e7fc396a5"), GattServiceType.Primary); _characteristic = new BluetoothGattCharacteristic(UUID.FromString("d8de624e-140f-4a22-8594-e2216b84a5f2"), GattProperty.Read | GattProperty.Notify | GattProperty.Write, GattPermission.Read | GattPermission.Write); _characteristic.AddDescriptor(new BluetoothGattDescriptor(UUID.FromString("28765900-7498-4bd4-aa9e-46c4a4fb7b07"), GattDescriptorPermission.Read | GattDescriptorPermission.Write)); service.AddCharacteristic(_characteristic); _bluetoothServer.AddService(service); _bluettothServerCallback.CharacteristicReadRequest += _bluettothServerCallback_CharacteristicReadRequest; _bluettothServerCallback.NotificationSent += _bluettothServerCallback_NotificationSent; Console.WriteLine("Server created!"); BluetoothLeAdvertiser myBluetoothLeAdvertiser = _bluetoothAdapter.BluetoothLeAdvertiser; var builder = new AdvertiseSettings.Builder(); builder.SetAdvertiseMode(AdvertiseMode.LowLatency); builder.SetConnectable(true); builder.SetTimeout(0); builder.SetTxPowerLevel(AdvertiseTx.PowerHigh); AdvertiseData.Builder dataBuilder = new AdvertiseData.Builder(); dataBuilder.SetIncludeDeviceName(true); //dataBuilder.AddServiceUuid(ParcelUuid.FromString("ffe0ecd2-3d16-4f8d-90de-e89e7fc396a5")); dataBuilder.SetIncludeTxPowerLevel(true); myBluetoothLeAdvertiser.StartAdvertising(builder.Build(), dataBuilder.Build(), new BleAdvertiseCallback()); }
/** * Initializes a reference to the local Bluetooth adapter. * * @return Return true if the initialization is successful. */ public bool Initialize() { // For API level 18 and above, get a reference to BluetoothAdapter through // BluetoothManager. if (mBluetoothManager == null) { mBluetoothManager = (BluetoothManager) GetSystemService (Context.BluetoothService); if (mBluetoothManager == null) { Log.Error (TAG, "Unable to initialize BluetoothManager."); return false; } } mBluetoothAdapter = mBluetoothManager.Adapter; if (mBluetoothAdapter == null) { Log.Error (TAG, "Unable to obtain a BluetoothAdapter."); return false; } return true; }
public TricorderBluetoothManager(bt.BluetoothManager bluetoothManager) { this.PlatformManager = bluetoothManager; }