Please note that as of October 24, 2014, the Nokia Developer Wiki will no longer be accepting user contributions, including new entries, edits and comments, as we begin transitioning to our new home, in the Windows Phone Development Wiki. We plan to move over the majority of the existing entries. Thanks for all your past and future contributions.

How to create a Bluetooth connection that can be used across your Windows Phone app

From Wiki
Jump to: navigation, search

This article explains how to create a Bluetooth connection that can be used in any page of a Windows Phone application.

WP Metro Icon WP8.png
Article Metadata
Code ExampleTested with
Devices(s): Lumia 820, Lumia 620
Platform(s): Windows Phone 8.0 and later
Windows Phone 8
Created: ceriboo (06 May 2013)
Last edited: hamishwillee (04 Jul 2013)



The Dev Center documentation shows how to create and use a Bluetooth connection using a new StreamSocket. However in a real app you won't create a connection every time, but instead create a single instance to be used across your whole app.

This article shows how you can create a connection that works across all pages. Note that Bluetooth stream sockets only work with Windows Phone 8 and later.


The solution is to create a static StreamSocket as part of your App class. This can then be referenced throughout your app using its full scope.

Declare the static StreamSocket in App.xaml.cs as shown:

public static StreamSocket Socket;

To use this socket in a page you can reference it using its full scope App.Socket. The line below shows how you'd create the socket.

App.Socket = new StreamSocket();

Bluetooth for Windows Phone 8 shows in more detail how to find a Bluetooth device using PeerFinder, connect to it using Socket::ConnectAsync(), and send and receive information using App.Socket.OutputStream.WriteAsync and App.odbSocket.InputStream.ReadAsync as appropriate.

Code Sample

This code sample shows how to find peers and connect to them in several pages.


This article showed how to create a static Bluetooth connection that can be used through your app.

This approach has been verified in the test app, and also my commercial apps:


Bluetooth for Windows Phone 8 (Dev Center)


This article was only possible with super advice from my Facebook friend Olivier Bacheliez.

This page was last modified on 4 July 2013, at 01:45.
81 page views in the last 30 days.