LSconnect.Bluetooth.Android
2.0.0
See the version list below for details.
dotnet add package LSconnect.Bluetooth.Android --version 2.0.0
NuGet\Install-Package LSconnect.Bluetooth.Android -Version 2.0.0
<PackageReference Include="LSconnect.Bluetooth.Android" Version="2.0.0" />
<PackageVersion Include="LSconnect.Bluetooth.Android" Version="2.0.0" />
<PackageReference Include="LSconnect.Bluetooth.Android" />
paket add LSconnect.Bluetooth.Android --version 2.0.0
#r "nuget: LSconnect.Bluetooth.Android, 2.0.0"
#:package LSconnect.Bluetooth.Android@2.0.0
#addin nuget:?package=LSconnect.Bluetooth.Android&version=2.0.0
#tool nuget:?package=LSconnect.Bluetooth.Android&version=2.0.0
Cross-Platform Support
This package is multi-targeted:
net8.0– platform-agnostic abstraction layernet8.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()→ returnsQualityResult
Internally uses InTheHand.Net.Bluetooth.
Installation
- Add the NuGet package LSconnect.Bluetooth.Android to your .NET MAUI Android project.
- Ensure your project targets
net8.0-android. - 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();
Or use automatic disposal:
await using var terminal = BluetoothTerminalFactory.Create();
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); }
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. net8.0-android was computed. net8.0-android34.0 is compatible. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net8.0
- No dependencies.
-
net8.0-android34.0
- InTheHand.Net.Bluetooth (>= 4.1.40)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.