问题描述
我尝试通过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
Internet(客户端和服务器)功能无法解决问题.为什么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蓝牙的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!