流套接字访问被拒绝 Windows Phone 8.1 蓝牙 [英] Stream Socket Access denied Windows Phone 8.1 Bluetooth

查看:25
本文介绍了流套接字访问被拒绝 Windows Phone 8.1 蓝牙的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试使用 StreamSocket-Class 将蓝牙设备与我的 Windows Phone (8.1) 连接.

I try to connect a Bluetooth device with my Windows Phone (8.1) with the StreamSocket-Class.

现在每次我调用 socket.CallAsync(HostName, RemoteServiceName) 时都会收到 AccessDenied 错误.我在 AppManifest 中激活了接近传感器.

Now every time I call socket.CallAsync(HostName, RemoteServiceName) I get an AccessDenied Error. I activated the Proximity sensor in the AppManifest.

代码如下:

private async void ConnectToDevice()
    {
        if (_socket != null)
        {
            // Disposing the socket with close it and release all resources associated with the socket
            _socket.Dispose();
        }

        try
        {
            _socket = new StreamSocket();

            // Note: If either parameter is null or empty, the call will throw an exception
            await _socket.ConnectAsync(_currentPeer.HostName, "{00001101-0000-1000-8000-00805f9b34fb}");

            // If the connection was successful, the RemoteAddress field will be populated
            MessageDialog md = new MessageDialog(_socket.Information.RemoteAddress.DisplayName);
            await md.ShowAsync();

            Start.IsEnabled = true;
        }
        catch (Exception ex)
        {
            MessageDialog md = new MessageDialog("Connection failed");
            await md.ShowAsync();

            _socket.Dispose();
            _socket = null;
        }
    }

感谢您的帮助!

推荐答案

我遇到了同样的问题.但最后我在 http://www.codefest.at/post/2014/02/03/Bluetooth-in-Windows-81-Apps-nutzen.aspx

I had the same issue. But finally I've found a solution at http://www.codefest.at/post/2014/02/03/Bluetooth-in-Windows-81-Apps-nutzen.aspx

互联网(客户端和服务器)功能不起作用.为什么 MS 没有在 Visual Studio 的 GUI 中提供蓝牙功能,这对我来说是个谜.

The Internet (Client & Server) capability doesn't do the trick. It's a riddle to me why MS doesn't provide the bluetooth capability in the GUI of Visual Studio.

只需将以下 xml 添加到您的 appxmanifest 中:

Just add the following xml into your appxmanifest:

<Capabilities>
    <m2:DeviceCapability Name="bluetooth.rfcomm">
      <m2:Device Id="any">
        <m2:Function Type="serviceId:00001101-0000-1000-8000-00805F9B34FB" />
      </m2:Device>
    </m2:DeviceCapability>
  </Capabilities>

问候

这篇关于流套接字访问被拒绝 Windows Phone 8.1 蓝牙的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆