建立藍芽 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();
注意:這僅適用於前臺廣告(應用程式開啟時)。