【问题标题】:Can only retrieve all Services when trying to get Paired Bluetooth Devices尝试获取配对的蓝牙设备时只能检索所有服务
【发布时间】:2014-10-11 10:03:33
【问题描述】:

我正在编写一个带有 SPP 的 Windows/Windows Phone 8.1 蓝牙应用程序,最终用户需要选择要使用的配对蓝牙设备。

问题 1:

我在尝试仅获取与我的设备配对的已配对蓝牙设备时遇到问题。我只能在设备上获得所有服务。

注意:我使用的是与 Windows 7 笔记本电脑配对的 Windows Phone 8.1 设备

DeviceInformationCollection CollectionOfDeviceInfo;

PeerFinder.AlternateIdentities["Bluetooth:Paried"] = ""; 

//CollectionOfDeviceInfo = await DeviceInformation.FindAllAsync(RfcommDeviceService.GetDeviceSelector(RfcommServiceId.SerialPort)); 
CollectionOfDeviceInfo = await DeviceInformation.FindAllAsync();

FindAllAsync() 为我提供了手机上的所有服务,包括配对的蓝牙和所有这些服务。

问题 #2:

我不知道我需要 SPP 蓝牙提供的哪些服务。如果我知道我需要从蓝牙提供的服务,我会从庞大的服务列表中筛选出来。

我一直在看 BluetoothRfcommChat 和 BluetoothCommunicationSample 来自 MSDN,但它没有帮助。

【问题讨论】:

    标签: c# bluetooth windows-phone-8.1 rfcomm


    【解决方案1】:

    哈,我让 RfcommServiceId.SerialPort 工作了。需要添加

    <Capabilities>
      <m2:DeviceCapability Name="bluetooth.rfcomm">
        <m2:Device Id="any">
          <m2:Function Type="name.serialPort"/>
        </m2:Device>
      </m2:DeviceCapability>
    </Capabilities>
    

    到我的 Package.appxmanifest(提示:右键单击->查看代码)

    那么我的台词

    CollectionOfDeviceInfo = await DeviceInformation.FindAllAsync(RfcommDeviceService.GetDeviceSelector(RfcommServiceId.SerialPort));
    

    效果很好。

    为了解决这个问题,我让BluetoothRfcommChat 在 Windows 8.1 笔记本电脑和我的 Winows Phone 8.1 设备上工作。我确实需要在配对后重新启动笔记本电脑,并从启动磁贴而不是调试运行应用程序。手机端我不需要重启,可以从调试中运行。

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-04-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-01-26
    相关资源
    最近更新 更多