David Lee
David Lee

Reputation: 23

BluetoothLEAdvertisementWatcher.Received is not called in C++/CX

C++ experts! Now I am developing c++/CX UWP application to connect bluetooth device. For this, I am going to use BluetoothLEAdvertisementWatcher. As you know, to scan devices, it is needed to call BluetoothLEAdvertisementWatcher.Received event. To do so, I declared function connecting to this event and called BluetoothLEAdvertisementWatcher.Start function. But BluetoothLEAdvertisementWatcher.Received handler is not called. If anyone knows, please help me. My application is for UWP.

Bluetooth::Advertisement::BluetoothLEAdvertisementWatcher^ bleAdvertisementWatcher;
MainPage::MainPage()
{
    InitializeComponent();
    initApp();
}
void BluetoothConnector::MainPage::initApp()
{
    bleAdvertisementWatcher = ref new Bluetooth::Advertisement::BluetoothLEAdvertisementWatcher();
    bleAdvertisementWatcher->ScanningMode = Bluetooth::Advertisement::BluetoothLEScanningMode::Active;
    bleAdvertisementWatcher->Received += ref new Windows::Foundation::TypedEventHandler<Bluetooth::Advertisement::BluetoothLEAdvertisementWatcher^, Windows::Devices::Bluetooth::Advertisement::BluetoothLEAdvertisementReceivedEventArgs^>(
        [](Bluetooth::Advertisement::BluetoothLEAdvertisementWatcher^ watcher, Bluetooth::Advertisement::BluetoothLEAdvertisementReceivedEventArgs^ eventArgs) {//event delegate handler
            do_something;
        });
}
void BluetoothConnector::MainPage::Button_Click_Search(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)
{
    bleAdvertisementWatcher->Start();
}

As far as I know, if it calls BluetoothLEAdvertisementWatcher.Start, it starts to scan devices and receives devices information. But received event function is never called. Please correct me. Thank you.

Upvotes: 0

Views: 638

Answers (0)

Related Questions