How to set UUID for BluetoothLEAdvertisementPublisher ?

Jacob Jiang 1 Reputation point Microsoft Employee
2022-03-25T15:51:28.437+00:00

Here there, I planned to do something on Windows broadcast something so my iOS device can find me and start connect to me.

So I look into the BluetoothLEAdvertisementPublisher API, it turns out no way to set the BluetoothLEAdvertisement nor change/add any GUID to it.
If I initiate the BluetoothLEAdvertisementPublisher with a BluetoothLEAdvertisement, BluetoothLEAdvertisementPublisher still can't set GUID, it's read only.

Then it looks to me, the only thing are changable is "Manufactor Data", which looks way limited for me.

Is there something we could change?

Developer technologies | Universal Windows Platform (UWP)
{count} votes

1 answer

Sort by: Most helpful
  1. Anonymous
    2022-03-28T05:45:28.6+00:00

    Hello,

    Welcome to Microsoft Q&A!

    Is there something we could change?

    No, based on the BluetoothLEAdvertisementPublisher and BluetoothLEAdvertisement, the ServiceUuids property is not a changeable for users. And yes, as you've seen, the ManufacturerData is where you could set the UUID.

    Like this:

      // Create and initialize a new publisher instance.  
                publisher = new BluetoothLEAdvertisementPublisher();  
      
                // We need to add some payload to the advertisement. A publisher without any payload  
                // or with invalid ones cannot be started. We only need to configure the payload once  
                // for any publisher.  
      
                // Add a manufacturer-specific section:  
                // First, let create a manufacturer data section  
                var manufacturerData = new BluetoothLEManufacturerData();  
      
                // Then, set the company ID for the manufacturer data. Here we picked an unused value: 0xFFFE  
                manufacturerData.CompanyId = 0xFFFE;  
      
                // Finally set the data payload within the manufacturer-specific section  
                // Here, use a 16-bit UUID: 0x1234 -> {0x34, 0x12} (little-endian)  
                var writer = new DataWriter();  
                UInt16 uuidData = 0x1234;  
                writer.WriteUInt16(uuidData);  
      
                // Make sure that the buffer length can fit within an advertisement payload. Otherwise you will get an exception.  
                manufacturerData.Data = writer.DetachBuffer();  
      
                // Add the manufacturer data to the advertisement publisher:  
                publisher.Advertisement.ManufacturerData.Add(manufacturerData);  
    

    You could also check the code in the official Bluetooth sample here: BluetoothAdvertisement.

    Thank you.


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.