LSconnect.Bluetooth.Android 4.0.0

dotnet add package LSconnect.Bluetooth.Android --version 4.0.0
                    
NuGet\Install-Package LSconnect.Bluetooth.Android -Version 4.0.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="LSconnect.Bluetooth.Android" Version="4.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="LSconnect.Bluetooth.Android" Version="4.0.0" />
                    
Directory.Packages.props
<PackageReference Include="LSconnect.Bluetooth.Android" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add LSconnect.Bluetooth.Android --version 4.0.0
                    
#r "nuget: LSconnect.Bluetooth.Android, 4.0.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package LSconnect.Bluetooth.Android@4.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=LSconnect.Bluetooth.Android&version=4.0.0
                    
Install as a Cake Addin
#tool nuget:?package=LSconnect.Bluetooth.Android&version=4.0.0
                    
Install as a Cake Tool

Architecture

This package provides the Android implementation of the LSconnect.Bluetooth abstraction layer.

The solution is structured into:

  • platform-agnostic contract layer
  • platform-specific implementation layer

Cross-Platform Support

This package is multi-targeted:

  • net8.0 – platform-agnostic abstraction layer
  • net8.0-android – Android implementation using InTheHand.Net.Bluetooth

The shared API is available in the LSconnect.Bluetooth namespace and can be used from common (.NET MAUI shared) code.

On Android, the factory returns a fully functional Bluetooth implementation.

On non-Android platforms (iOS, Windows, macOS), the factory returns a stub implementation that throws PlatformNotSupportedException.

LSconnect.Bluetooth.Android

A lightweight Bluetooth Serial wrapper for .NET MAUI Android applications, designed for communication with devices that send text-based data over Bluetooth.
This package is specialized for a milk analyzer that outputs tab-separated measurement results, but the Bluetooth API remains generic and reusable.

Features

  • Bluetooth device discovery (SearchAsync)
  • Optional filtering of paired-only devices (pairedOnly)
  • Connecting to a Bluetooth device (ConnectAsync)
  • Sending text (SendTextAsync)
  • Receiving text (ReceiveTextAsync)
  • Explicit disconnection (DisconnectAsync)
  • Utility helpers for text processing (BluetoothTextUtils)
  • High-level API for reading milk quality results:
    • ReadQualityParametersAsync() → returns QualityResult

Internally uses InTheHand.Net.Bluetooth.


Installation

  1. Add the NuGet package LSconnect.Bluetooth.Android to your .NET MAUI Android project.
  2. Ensure your project targets net8.0-android.
  3. Declare and request the required Bluetooth permissions.

Android Permissions

This library does not request runtime permissions automatically.
Your application must declare and request them manually.

Example Platforms/Android/AndroidManifest.xml:

xml <uses-permission android:name="android.permission.BLUETOOTH" /> <uses-permission android:name="android.permission.BLUETOOTH_ADMIN" /> <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

<uses-permission android:name="android.permission.BLUETOOTH_SCAN" /> <uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />


Usage (from shared MAUI code)

csharp using LSconnect.Bluetooth;

var terminal = BluetoothTerminalFactory.Create();

var devices = await terminal.SearchAsync(pairedOnly: true);

await terminal.ConnectAsync(devices.First());

var result = await terminal.ReadQualityParametersAsync();

await terminal.DisconnectAsync();

Basic usage

Create a terminal

IBluetoothTerminal terminal = BluetoothTerminalFactory.Create();

Search for devices

var devices = await terminal.SearchAsync(); var pairedDevices = await terminal.SearchAsync(pairedOnly: true);

Connect to a device

await terminal.ConnectAsync(device);

Send text

await terminal.SendTextAsync("Hello!");

Receive text

var response = await terminal.ReceiveTextAsync();

Disconnect

await terminal.DisconnectAsync();

Paired Devices

When SearchAsync(pairedOnly: true) is used on Android, the package reads the bonded device list directly from the Android Bluetooth adapter.

This makes paired device discovery more reliable than filtering discovery results by authentication state.

Or use automatic disposal:

await using var terminal = BluetoothTerminalFactory.Create();

Connect by Known Device Address

The package also supports direct connection using a previously known Bluetooth device address:

using LSconnect.Bluetooth;

var terminal = BluetoothTerminalFactory.Create();

await terminal.ConnectAsync("00:11:22:33:44:55");

Milk Analyzer Integration

The analyzer sends a single line of tab-separated data in the following format:

"RES\t" + <fields> + "\r\n"

The prefix RES indicates that measurement results follow. All fields are separated by TAB (\t).

QualityResult Model

public class QualityResult { public string Date { get; set; } public string Time { get; set; } public string Supplier { get; set; } public string DeliveryName { get; set; } public string Litres { get; set; } public string SerialNumber { get; set; }

public double Cal { get; set; }
public double Temp { get; set; }
public double Fat { get; set; }
public double SNF { get; set; }
public double Density { get; set; }
public double Protein { get; set; }
public double Lactose { get; set; }
public double Water { get; set; }
public double Solids { get; set; }
public double Conductivity { get; set; }
public double Ph { get; set; }
public double FreezingPoint { get; set; }
public double TotalSolids { get; set; }

}

Reading a Measurement Result

var result = await terminal.ReadQualityParametersAsync();

if (result != null) { Console.WriteLine($"Fat: {result.Fat}"); Console.WriteLine($"Density: {result.Density}"); }

ReadQualityParametersAsync() performs:

Reading one Bluetooth message

Normalizing CR/LF

Splitting the line by TAB

Validating the prefix RES

Parsing fields into QualityResult

Converting numeric values using invariant culture

Utility: BluetoothTextUtils public static class BluetoothTextUtils { public static string Normalize(string? input); public static string[] SplitFields(string? input, char separator); public static string[] SplitTabSeparated(string? input); }

Important Notes

  • Bluetooth functionality is supported only on Android.
  • The package can still be referenced from shared MAUI code because it provides a platform-agnostic abstraction layer.
  • On non-Android platforms, Bluetooth calls throw PlatformNotSupportedException.
  • Android Bluetooth permissions must still be declared and requested by the application.
  • SearchAsync(pairedOnly: true) uses Android bonded devices.
Product Compatible and additional computed target framework versions.
.NET net8.0-android34.0 is compatible.  net9.0-android was computed.  net10.0-android was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
4.0.0 97 4/30/2026
3.0.0 95 4/22/2026
2.1.0 99 4/21/2026
2.0.0 113 2/25/2026
1.1.0 408 11/20/2025
1.0.2 410 11/20/2025
1.0.1 404 11/19/2025
1.0.0 418 11/18/2025