Set Advertisement.Flags() will cause exception when BluetoothLEAdvertisementPublisher start.

frank zhang 121 Reputation points
2022-08-14T09:55:47.817+00:00

On my windows10, run code below to do ble advertisement:

auto publisher = Bluetooth::Advertisement::BluetoothLEAdvertisementPublisher();  
  
// Add custom data to the advertisement  
auto manufacturerData = Bluetooth::Advertisement::BluetoothLEManufacturerData();  
manufacturerData.CompanyId(0xaaaa);  
auto writer = DataWriter();  
writer.WriteByte('1');  
writer.WriteByte('2');  
writer.WriteByte('3');  
  
manufacturerData.Data() = writer.DetachBuffer();  
publisher.Advertisement().ManufacturerData().Append(manufacturerData);  
publisher.UseExtendedAdvertisement(true);  
  
publisher.Advertisement().Flags(Bluetooth::Advertisement::BluetoothLEAdvertisementFlags::GeneralDiscoverableMode); //set adv flags  
printf("publisher flags :%d", publisher.Advertisement().Flags().Value()); // log shows flags was set.  
  
publisher.Start(); //meet winrt::hresult_invalid_argument here...  

I try the code above without "set Advertisement flags" and the code can run successfully, but the ble advertisement can not be discoveried. So I think advertisement flags should be set ? Then if flags is set ,how to deal with with the exception? If I have missed other params should be set together then cause the exception?

Universal Windows Platform (UWP)
Windows API - Win32
Windows API - Win32
A core set of Windows application programming interfaces (APIs) for desktop and server applications. Previously known as Win32 API.
2,410 questions
{count} votes

Accepted answer
  1. Roy Li - MSFT 31,551 Reputation points Microsoft Vendor
    2022-08-24T02:19:03.01+00:00

    Hello,

    Welcome to Microsoft Q&A!

    But what puzzles me now is that why MircoSoft ble api could not set it, for it is a basic function for ble advertisement, and the restriction is weird...

    After consulting the Bluetooth team, I got more information about this behavior. First of all, yes, the system reserves this type of advertisement and that is the reason for error.

    As you could see in the document, there are other flags that are reserved by the system. The system reserves these flags because they are used as part of other APIs and the advertisement API does not allow it to interfere with other APIs on the system. Currently, Windows does not support low-level access to Bluetooth functionalities in general.

    Also, the Bluetooth team said that: This particular policy might be revisited in the future in the case when extended advertisement is supported as each API has its own advertising set allocation. However, this remains blocked today.

    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

0 additional answers

Sort by: Most helpful