Transferring data via Bluetooth

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.

How to do it...

We can set up our app to listen for Bluetooth devices that we can communicate with:

  1. As with normal Bluetooth access, we need to have the apropriate permissions, such as Bluetooth and BluetoothAdmin, before we can transmit data via Bluetooth:
    [assembly: UsesPermission(Manifest.Permission.Bluetooth)]
    [assembly: UsesPermission(Manifest.Permission.BluetoothAdmin)]
  2. 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"; ...

Get Xamarin Mobile Development for Android Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.