I'm trying to use BluetoothLEAdvertisementWatcher to detect BLE advertising packets. However upon calling Start() the watcher object always aborts with 'Access is denied' error.
Code is pretty simple and is as below:
auto filter = BluetoothLEAdvertisementFilter();
auto advert = BluetoothLEAdvertisement();
advert.LocalName(L"Greeny");
filter.Advertisement(advert);
m_watcher.AdvertisementFilter(filter);
// setup event handlers
m_watcher.Received({ this, &MainPage::OnAdvertisementRecieved });
m_watcher.Stopped({ this, &MainPage::OnAdvertisementStopped });
m_watcher.Start();
m_watcher is a class member declared as:
BluetoothLEAdvertisementWatcher m_watcher;
The event handlers are declared as:
void MainPage::OnAdvertisementRecieved(BluetoothLEAdvertisementWatcher const& watcher, BluetoothLEAdvertisementReceivedEventArgs const& args)
{
OutputDebugString(L"Bluetooth advertisement received!
");
}
void MainPage::OnAdvertisementStopped(Windows::Devices::Bluetooth::Advertisement::BluetoothLEAdvertisementWatcher const & watcher, Windows::Devices::Bluetooth::Advertisement::BluetoothLEAdvertisementWatcherStoppedEventArgs const & args)
{
OutputDebugString(L"Advertising stopped
");
}
This code is pretty similar to the sample code in the SDK which is in C#. I'm trying to do the same in C++ as I'm more familiar with it.
Any idea what could be going wrong? I tried removing all the filters, that is, using the watcher in its default state. That too gives the same error. Removing the event handlers also results in the same error.
Thanks in advance.
EDIT: Changed the title adding ERROR_ACCESS_DENIED.
EDIT2: The exact location where the error occurs is:
onecoreuapdriverswdmluetoothuserwinrtadvertisementluetoothleadvertisementwatcher.cpp(1510)Windows.Devices.Bluetooth.dll!0F479314: (caller: 0F47AD40) Exception(2) tid(2c1c) 80070005 Access is denied.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…