Cong Tran
Cong Tran

Reputation: 1458

listening bluetooth device connecting windows phone

I have a project in Windows Phone 8 that connects two devices via Bluetooth. When I try to connect my phone and the other device, my phone is listening/waiting for the connection from my other device. But when my device sends the request to connect, the PeerFinder_ConnectionRequested event doesn't fire. My code:

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;
}

Can anyone see what I'm doing wrong?

Upvotes: 1

Views: 799

Answers (1)

BorisT
BorisT

Reputation: 138

have you started peerfinder?

PeerFinder.Start()

Upvotes: 1

Related Questions