public Task StartAdvertising(AdvertisementData adData = null) { this.publisher.Advertisement.Flags = BluetoothLEAdvertisementFlags.ClassicNotSupported; this.publisher.Advertisement.ManufacturerData.Clear(); this.publisher.Advertisement.ServiceUuids.Clear(); if (adData?.ManufacturerData != null) { using (var writer = new DataWriter()) { writer.WriteBytes(adData.ManufacturerData.Data); var md = new BluetoothLEManufacturerData(adData.ManufacturerData.CompanyId, writer.DetachBuffer()); this.publisher.Advertisement.ManufacturerData.Add(md); } } if (adData?.ServiceUuids != null) { foreach (var serviceUuid in adData.ServiceUuids) { this.publisher.Advertisement.ServiceUuids.Add(serviceUuid); } } this.publisher.Start(); return(Task.CompletedTask); }
public async Task StartAdvertising(AdvertisementData adData = null) { if (this.manager.Advertising) { throw new ArgumentException("Advertising is already active"); } await this.manager.WhenReady().ToTask(); this.manager.StartAdvertising(new StartAdvertisingOptions { LocalName = adData?.LocalName, ServicesUUID = adData? .ServiceUuids? .Select(x => x.ToCBUuid()) .ToArray() }); }
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); }