听蓝牙设备连接Windows手机

时间:2013-03-24 03:38:15

标签: c# windows-phone-7 bluetooth windows-phone-8

我在Windows Phone 8中有一个项目,通过蓝牙连接两台设备。当我尝试连接手机和其他设备时,我的手机正在侦听/等待来自其他设备的连接。但是当我的设备发送连接请求时,PeerFinder_ConnectionRequested事件不会触发。我的代码:

public MainPage()
{
   InitializeComponent();
   Loaded += MainPage_Loaded;
}

void MainPage_Loaded(object sender, RoutedEventArgs e)
{
   PeerFinder.ConnectionRequested += PeerFinder_ConnectionRequested;
}

void PeerFinder_ConnectionRequested(object sender, ConnectionRequestedEventArgs args)
{
   if (ShouldConnect())
    {
       // Go ahead and connect
       ConnectToPeer(args.PeerInformation);
    }
}

async void ConnectToPeer(PeerInformation peer)
{
   StreamSocket socket = await PeerFinder.ConnectAsync(peer);
   MessageBox.Show ("Completed");
}

private bool ShouldConnect()
{
   // Determine whether to accept this connection request and return
   return true;
}

谁能看到我做错了什么?

1 个答案:

答案 0 :(得分:1)

你有没有开始使用peerfinder?

PeerFinder.Start()