搜索插件、代码仓与 APP 分类

插件详情v0.1.1

flutter_blue_classic

用于与蓝牙经典设备通信的 Flutter 插件

Android
近 30 天下载
3290
喜欢数
37
Pub 分数
160

安装插件

flutter pub add flutter_blue_classic

插件介绍

基于插件公开信息、社区数据与项目使用情况整理的选型参考。

flutter_blue_classic 是一个 Flutter 插件,可在 Android 上实现与蓝牙经典设备的通信。它提供了一个简单的 API,用于发现、连接并交换数据给经典蓝牙外设。专为需要与旧式蓝牙硬件(如音频设备、传感器或自定义物联网设备)交互的应用程序而设计,可无缝集成到 Flutter 应用中。该插件支持扫描、配对以及处理已连接设备的数据流等基本蓝牙操作。由 lenhart.dev 维护,并托管在 GitHub 上,以确保透明度和社区贡献。

适合场景

  • 连接到旧版蓝牙音频设备
  • 与自定义蓝牙传感器通信
  • 构建物联网控制应用程序
  • 在安卓设备之间传输数据
  • 开发工业或医疗蓝牙工具

主要特点

  • 仅支持 Android
  • 蓝牙经典协议兼容性
  • 实时数据流
  • 设备发现和连接管理
  • 简单的事件驱动 API

适合对象

  • 面向 Android 的蓝牙应用开发
  • 需要经典蓝牙集成的项目
  • 使用较旧蓝牙硬件的开发人员
  • 物联网和基于传感器的应用
  • 原型设计蓝牙解决方案

使用建议

  • 仅限Android平台
  • 不支持蓝牙 LE
  • 需要 Android 权限以访问蓝牙
  • 可能需要额外的设备特定配置
  • 依赖外部原生蓝牙库

原始 README

以下为关联源码仓库的 README 原文快照,最新内容请访问源码仓库。

flutter_blue_classic

Flutter_blue_classic is a flutter plugin for communicating with bluetooth classic devices. If you want to use an Bluetooth low energy (BLE) device, you might want to consider flutter_blue_plus.

A note on iOS

This plugin is currently only compatible with Android. iOS does not provide a similar interface for Bluetooth Classic like Android does. On iOS your BL device must be MFi (Made for iPod/iPhone) certified and you will have to use the External Accessory Framework. Since this is out of the scope of this package, you will have to implement this yourself.

Getting Started

minSdkVersion

This package is only compatible with Android SDK 21 or higher. Please set your minSdkVersion in the android/app/build.gradle accordingly.

Permissions

As the Android permission requirements can differ from case to case, this package does not define any permissions in it's Manifest. It is therefore necessary to declare them yourself. For detailed information, take a look at the Android Developer Documentation on Permissions.

Below are two common presets:

Without location access

In the android/app/src/main/AndroidManifest.xml add:

<!-- Permissions for Android 12 or above -->
<uses-permission android:name="android.permission.BLUETOOTH_SCAN" android:usesPermissionFlags="neverForLocation" />
<uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />

    <!-- legacy for Android 11 or lower -->
<uses-permission android:name="android.permission.BLUETOOTH" android:maxSdkVersion="30" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" android:maxSdkVersion="30" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" android:maxSdkVersion="30" />

    <!-- legacy for Android 9 or lower -->
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" android:maxSdkVersion="28" />
With location access

In the android/app/src/main/AndroidManifest.xml add:

<!-- Permissions for Android 12 or above -->
<uses-permission android:name="android.permission.BLUETOOTH_SCAN" />
<uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

    <!-- legacy for Android 11 or lower -->
<uses-permission android:name="android.permission.BLUETOOTH" android:maxSdkVersion="30" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" android:maxSdkVersion="30" />

    <!-- legacy for Android 9 or lower -->
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" android:maxSdkVersion="28" />

Then pass the accessFineLocation parameter when initializing the plugin:


final blueClassic = FlutterBlueClassic(usesFineLocation: true);

Reference

FlutterBlueClassic
Description
isSupported Checks whether the device supports Bluetooth
isEnabled Checks whether Bluetooth is enabled
adapterStateNow Current state of the bluetooth adapter
adapterState Stream of on, off and intermediary states of the bluetooth adapter
bondedDevices Returns the list of bonded (paired) devices
startScan Starts a scan for Bluetooth devices
stopScan Stop an existing scan for Bluetooth devices
isScanningNow Checks whether the Bluetooth adapter is currently scanning.
isScanning Stream whether the device is scanning for BL devices.
scanResults Stream of found devices during scan
turnOn Requests to turn the bluetooth adapter on
bondDevice Requests to create a bond with a bluetooth device
connect Tries to connect with a bluetooth device
BluetoothConnection
Description
input The stream of data received from the connected BL device
output A stream sink to send byte data to the connected BL device
writeString A helper to send utf-8 encoded strings to the remote device
isConnected Indicates whether the connection is still open.
dispose This should be called, when the Connection is no longer needed and will call finish (see below).
finish This will wait for any ongoing writes to be finished and gracefully close the connection.
close This will immediately close the connection.

Acknowledgement

flutter_blue_classic is loosely based on flutter_bluetooth_serial.

所属分类

依赖

依赖清单 1 项

  • plugin_platform_interface^2.0.2

源码仓库

使用此插件的项目

暂无相关数据。