创建蓝牙 LE 广告

此示例显示如何从前台的 Windows 10 设备通告自定义有效内容。有效负载使用一个组合公司(标识为 0xFFFE)并在广告中通告字符串 Hello World

BluetoothLEAdvertisementPublisher publisher = new BluetoothLEAdvertisementPublisher();

// Add custom data to the advertisement
var manufacturerData = new BluetoothLEManufacturerData();
manufacturerData.CompanyId = 0xFFFE;

var writer = new DataWriter();
writer.WriteString("Hello World");

// Make sure that the buffer length can fit within an advertisement payload (~20 bytes). 
// Otherwise you will get an exception.
manufacturerData.Data = writer.DetachBuffer();

// Add the manufacturer data to the advertisement publisher:
publisher.Advertisement.ManufacturerData.Add(manufacturerData);

publisher.Start();

注意:这仅适用于前台广告(应用程序打开时)。