With Windows (and Phone) 8.1 there were two different device capabilities which needed to be set to use either RfComm or Bluetooth LE from your app. You had to specify a target device (or All) and target service name(s). With Windows 10 there is a simpler option. You still have to edit the appxmanifest code as it is not visible in the manifest designer but you can set simply:-
<DeviceCapability Name="bluetooth" />
This gives you access to all Bluetooth functionality from your app. This is a much simpler approach and less prone to errors. Most of the documentation doesn’t mention this new value except for this page:-
What’s different in Windows 10 Insider Preview
“new valid values are “bluetooth”, “wiFiControl”, “radios”, and “optical”.”
These are not mentioned on the “App capability declarations” page so it’s not clear which specific APIs the other intriguing values relate to…
As promised here are the resources from yesterday’s session on Bluetooth and NFC. I’ve begun uploading the slides and code to this SkyDrive folder:-
I have a few finishing touches to put on the sharing library for NFC – it will be up on NuGet and CodePlex shortly.
Version 8.1 of 32feet.NET for Windows Phone is now available via NuGet. This package adds some helper functionality for Bluetooth development. In particular this version includes the RfCommServiceId (designed to match the Windows 8.1 API) to provide information about various standard RfComm profiles. You can use this when connecting a StreamSocket or to filter devices in the BluetoothDevicePicker.
Speaking of which the BluetoothDevicePicker has been updated to more closely follow the appearance of the dialog displayed when you use the built in Bluetooth photo sharing feature. Currently the library is built with localized resources in mind but has only English text. If you are interested in providing localized text in your own language please contact me.
The CodePlex project contains the source and the Serial sample app. I’m working on some additional sample apps which will be added soon.
Unless you’ve been stuck under a rock (in which case what are you doing reading this?) you’ll know that Microsoft announced a preview release of Windows 8.1 at Build yesterday. While I haven’t got a development machine up and running yet (No easy upgrade if your device is UK English) I’ve been looking at the updated documentation at MSDN. Of the many new APIs described there are a couple of new namespaces which will be interesting to those working with Bluetooth devices:-
Windows.Devices.Bluetooth.GenericAttributeProfile – Contains functionality to work with Bluetooth LE devices. This will make it possible to interact with devices such as FitBit and other low energy sensors and devices from within apps – which means support on ARM devices.
Windows.Devices.Bluetooth.Rfcomm – Support for normal serial sockets Bluetooth. While completely different from the Windows Phone 8 API it provides the same functionality and more. Ability to enumerate and get notified of device arrival and departure and access to SDP attributes. There are identifiers for a number of standard profiles – Generic File Transfer, ObexFileTransfer, ObexObjectPush, PhoneBookAccess (client and server), SerialPort (SPP).
A new Chat sample is available for 8.1 here – http://code.msdn.microsoft.com/windowsapps/Bluetooth-Rfcomm-Chat-afcee559
With the recent announcement of Windows Embedded Handheld 8 it seems fitting to discuss something related to industrial and line-of-business applications which you can develop now on the Windows Phone platform.
I’ve released the first drop of 32feet.NET for Windows Phone 8 to our CodePlex site and NuGet. Because the programming model on Windows Phone (based on Windows Runtime StreamSockets) this is a separate package and doesn’t follow the programming model of the main 32feet.NET release. Windows Phone 8 supports Bluetooth programming out-of-the-box it is not straight-forward as it is build around the Windows Runtime Peer networking APIs but is different to the Windows 8 implementation. The aim of the 32feet library for Windows Phone is to simplify common tasks. This initial release adds the following features:-
- Strongly typed extension methods for ConnectAsync which accept service Guids or numerical port numbers
- BluetoothDevicePicker which offers an easy way for a user to select a device. Equivalent to the SelectBluetoothDeviceDialog in the core 32feet library.
- Common Bluetooth service Guids
- Bluetooth Barcode scanner sample. This sample app connects to a Motorola CS3070 scanner and allows input of Barcodes to the device screen. It should also work with other Bluetooth serial based scanners.
This is just a first release and we will be continuing to develop the library as well as add further localisation and samples. For example to demonstrate connecting to applications running on the desktop (Sorry not Windows Store apps currently). Your feedback is valuable so please visit the CodePlex project site to provide feedback.
There is a NuGet package available for the Windows Phone flavour of 32feet.NET to allow you to easily add it to your projects:-
The Bluetooth API on Windows Phone 8 is based around some customisations to the Proximity APIs which are part of the Windows API introduced with Windows 8. When you “discover” devices you can retrieve a collection of device identifiers for paired devices. The first time you perform a task you will want to use this mechanism to select the appropriate device. However you may want your app to remember a specific device and try to connect again on subsequent attempts. In the old .NET world with 32feet.NET we have a constructor for BluetoothAddress which allows you to supply the address in a variety of string or numeric forms. In the Windows API the Windows.Networking.HostName type is used to represent a host name whether it is for a Bluetooth device or an IP address. Normally the read-only Type property will indicate the type of the host.
In order to store a Bluetooth address for later use you should save the RawName property which for Bluetooth devices is in the form “(11:22:33:44:55:66)”. The dotted hex notation is fairly common but notice the address is wrapped in brackets. Now to restore this address in a HostName instance you can later use to open a socket you can use:-
HostName storedHostName = new HostName(storedRawName);
You’ll notice that this sets the host name and correctly sets the Type property to Bluetooth.