Windows runtime DeviceInformation::FindAllAsync无法找到具有RFCOMM服务ID的设备
我想要一个带有两个Windows Phone的简单客户端/服务器设置,我使用以下代码来设置服务器:Windows runtime DeviceInformation::FindAllAsync无法找到具有RFCOMM服务ID的设备,windows-runtime,windows-phone-8.1,rfcomm,Windows Runtime,Windows Phone 8.1,Rfcomm,我想要一个带有两个Windows Phone的简单客户端/服务器设置,我使用以下代码来设置服务器: auto providerTask = create_task(RfcommServiceProvider::CreateAsync(RfcommServiceId::FromUuid(GetServiceGUID()))); providerTask.then([this](RfcommServiceProvider^ p) -> task < void > { th
auto providerTask = create_task(RfcommServiceProvider::CreateAsync(RfcommServiceId::FromUuid(GetServiceGUID())));
providerTask.then([this](RfcommServiceProvider^ p) -> task < void >
{
this->provider = p;
this->listener = ref new StreamSocketListener();
listener->ConnectionReceived += ref new Windows::Foundation::TypedEventHandler < Windows::Networking::Sockets::StreamSocketListener ^,
Windows::Networking::Sockets::StreamSocketListenerConnectionReceivedEventArgs ^ >
(this, &ConnectionManager::OnConnectionReceived);
return create_task(listener->BindServiceNameAsync(provider->ServiceId->AsString())).then([this]()
{
this->provider->StartAdvertising(listener);
});
}).then([](task<void> t)
{
//handle exceptions at the end of the chain
try
{
t.get();
}
catch (Platform::Exception^ ex)
{
if (ex->HResult == 0x9000000F)
{
OutputDebugString(L"Bluetooth is disabled.\n");
}
else throw ex;
}
});
对FindAllAsync的调用始终返回空集合,即使两个设备在设置中显示为成对。但是,如果在设置服务器和稍后枚举设备时使用RfcommServiceId::ObexObjectPush而不是FromUuid,则效果很好。有人知道为什么会发生这种情况吗?在这两种情况下,AQS选择器字符串是什么样子的 问题在于:
-山姆这更有帮助吗?不过,我想进行更多的调查。在这两种情况下,AQS选择器字符串是什么样子的?问题是:选择器与系统上的接口不匹配。过滤器用于匹配当前处于KM PnP状态的设备接口上的属性。如果接口的属性与选择器中逻辑请求的属性匹配,则会将其添加到设备信息集合中。
auto query = RfcommDeviceService::GetDeviceSelector(RfcommServiceId::FromUuid(GetServiceGUID()));
create_task(DeviceInformation::FindAllAsync(query))
.then([this](DeviceInformationCollection^ services)
{
if (services->Size > 0)
{
OutputDebugString(L"We've found a server!\n");
OutputDebugString(services->First()->Current->Name->Data());
}
});