Method FromBluetooth
FromBluetooth(BluetoothDevice)
Creates a NMEA LocationDataSource based on a bluetooth device port.
Declaration
[RequiresPermission("android.permission.BLUETOOTH")]
public static NmeaLocationDataSource FromBluetooth(BluetoothDevice device)
Parameters
Type | Name | Description |
---|---|---|
Android.Bluetooth.BluetoothDevice | device | The Bluetooth Serial service. |
Returns
Type | Description |
---|---|
NmeaLocationDataSource | A NMEA Location Datasource that reads from the specified bluetooth port |
Remarks
The created datasource will automatically handle creating and opening the specified serial port when the datasource is started. Once the datasource has been started, the NmeaDataStream will be available.
To use this device, ensure you have the necessary permissions set in the AndroidManifest.xml
file:
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.BLUETOOTH" />
To get a list of serial devices, use the serial-over-bluetooth UUID 00001101-0000-1000-8000-00805F9B34FB
to look for usable devices:
public static IEnumerable<BluetoothDevice> GetBluetoothSerialDevices()
{
Java.Util.UUID serial_uuid = Java.Util.UUID.FromString("00001101-0000-1000-8000-00805F9B34FB"); // Guid for bluetooth serial devices
var adapter = BluetoothAdapter.DefaultAdapter;
if (adapter != null && adapter.IsEnabled)
{
foreach (var b in adapter.BondedDevices.Where(d => d.GetUuids().Any(t => serial_uuid.CompareTo(t.Uuid) == 0)))
yield return b;
}
}
Applies to
Platforms and versions
Target | Versions |
---|---|
.NET Android | 200.2 - 200.5 |
Xamarin.Android | 100.10 - 100.14 |