LSconnect.Bluetooth.Android
1.0.2
See the version list below for details.
dotnet add package LSconnect.Bluetooth.Android --version 1.0.2
NuGet\Install-Package LSconnect.Bluetooth.Android -Version 1.0.2
<PackageReference Include="LSconnect.Bluetooth.Android" Version="1.0.2" />
<PackageVersion Include="LSconnect.Bluetooth.Android" Version="1.0.2" />
<PackageReference Include="LSconnect.Bluetooth.Android" />
paket add LSconnect.Bluetooth.Android --version 1.0.2
#r "nuget: LSconnect.Bluetooth.Android, 1.0.2"
#:package LSconnect.Bluetooth.Android@1.0.2
#addin nuget:?package=LSconnect.Bluetooth.Android&version=1.0.2
#tool nuget:?package=LSconnect.Bluetooth.Android&version=1.0.2
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" />
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-android34.0 is compatible. net9.0-android was computed. net10.0-android was computed. |
-
net8.0-android34.0
- InTheHand.Net.Bluetooth (>= 4.0.55)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.