We can transfer data to another device directly without having to use the Internet or any network infrastructure outside another device. Bluetooth allows one device to directly communicate with another device.
We can set up our app to listen for Bluetooth devices that we can communicate with:
As with normal Bluetooth access, we need to have the apropriate permissions, such as
Bluetooth
andBluetoothAdmin
, before we can transmit data via Bluetooth:[assembly: UsesPermission(Manifest.Permission.Bluetooth)] [assembly: UsesPermission(Manifest.Permission.BluetoothAdmin)]
Before we start the listener, we need to have a name that will be used to register it with the system:
const string ServiceName = "XamarinCookbookBluetooth";
Before two apps can communicate, they need to know about each other. This is achieved by providing a generated UUID that will be used by both devices:
const string Uuid = "25c0d296-0e78-4849-b70b-86f01f415add";
We start the listener...