public GattServer() { this.manager = (BluetoothManager)Application.Context.GetSystemService(Context.BluetoothService); this.adCallbacks = new AdvertisementCallbacks(); this.context = new GattContext(); this.runningSubj = new Subject <bool>(); }
public override void Start(AdvertisementData adData) { if (!CrossBleAdapter.AndroidConfiguration.IsServerSupported) { throw new BleException("BLE Advertiser needs API Level 23+"); } this.manager = (BluetoothManager)Application.Context.GetSystemService(Context.BluetoothService); this.adCallbacks = new AdvertisementCallbacks(); var settings = new AdvertiseSettings.Builder() .SetAdvertiseMode(AdvertiseMode.Balanced) .SetConnectable(adData.AndroidIsConnectable); var data = new AdvertiseData.Builder() .SetIncludeDeviceName(adData.AndroidUseDeviceName) .SetIncludeTxPowerLevel(true); if (adData.ManufacturerData != null) { data.AddManufacturerData(adData.ManufacturerData.CompanyId, adData.ManufacturerData.Data); } foreach (var serviceUuid in adData.ServiceUuids) { data.AddServiceUuid(serviceUuid.ToParcelUuid()); } if (string.IsNullOrEmpty(adData.LocalName) || adData.AndroidUseDeviceName) { this.manager .Adapter .BluetoothLeAdvertiser .StartAdvertising( settings.Build(), data.Build(), this.adCallbacks ); } else { this.manager .Adapter.SetName(adData.LocalName); var scanResponse = new AdvertiseData.Builder() .SetIncludeDeviceName(true); this.manager .Adapter .BluetoothLeAdvertiser .StartAdvertising( settings.Build(), data.Build(), scanResponse.Build(), this.adCallbacks ); } base.Start(adData); }
public void StopAdvertising() { this.context .Manager .Adapter .BluetoothLeAdvertiser .StopAdvertising(this.adCallbacks); this.adCallbacks = null; }
public Advertiser() { this.manager = (BluetoothManager)Application.Context.GetSystemService(Context.BluetoothService); this.adCallbacks = new AdvertisementCallbacks { Failed = e => IsStarted = false, Started = () => IsStarted = true }; }
public Task StartAdvertising(AdvertisementData adData = null) { // //if (!CrossBleAdapter.AndroidConfiguration.IsServerSupported) // // throw new BleException("BLE Advertiser needs API Level 23+"); this.adCallbacks = new AdvertisementCallbacks(); var settings = new AdvertiseSettings.Builder() .SetAdvertiseMode(AdvertiseMode.Balanced) .SetConnectable(true); var data = new AdvertiseData.Builder() .SetIncludeDeviceName(true) .SetIncludeTxPowerLevel(true); if (adData != null) { if (adData.ManufacturerData != null) { data.AddManufacturerData(adData.ManufacturerData.CompanyId, adData.ManufacturerData.Data); } if (adData.ServiceUuids != null) { foreach (var serviceUuid in adData.ServiceUuids) { data.AddServiceUuid(serviceUuid.ToParcelUuid()); } } } this.context .Manager .Adapter .BluetoothLeAdvertiser .StartAdvertising( settings.Build(), data.Build(), this.adCallbacks ); return(Task.CompletedTask); }
public Advertiser() { this.manager = (BluetoothManager)Application.Context.GetSystemService(Context.BluetoothService); this.adCallbacks = new AdvertisementCallbacks(); }