我想使用Windows Phone 8通过蓝牙传输阵列,所以我在MSDN上提到了以下介绍指南:http://msdn.microsoft.com/en-us/library/windows/apps/jj207007(v=vs.105).aspx
配对/连接非常简单,当我将应用程序部署到我的Lumia 620时,我能够使用上面的示例代码看到我配对的HTC Desire。接下来我尝试使用以下代码发送基本的5字节数组:
async void BLEfunc()
{
PeerFinder.AlternateIdentities["Bluetooth:Paired"] = "";
var peers = await PeerFinder.FindAllPeersAsync();
if (peers.Count == 0)
{
Details.Text = "No Device Found";
}
else
{
PeerInformation selectedPeers = peers[0];
StreamSocket socket = new StreamSocket();
await socket.ConnectAsync(selectedPeers.HostName, "1");
Details.Text = "Connected to device: " + selectedPeers.DisplayName; //Details is a TextBlock on screen
using (var dataWriter = new DataWriter(socket.OutputStream))
{
//byte[] DataArray = { 1, 2, 3, 4, 5 };
dataWriter.WriteByte(1);
var result = await dataWriter.StoreAsync();
dataWriter.DetachStream();
}
Details.Text = "Data sent!";
}
}
问题是程序在进入上述粘贴代码中的使用代码块时会遇到未处理的异常。到目前为止,一切都运行良好。我从这里得到了上述代码的想法:Sending files via bluetooth from winRT to android / WP devices
有什么想法吗?