搜尋套件、儲存庫與 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

原始碼儲存庫

使用此套件的專案

暫無相關資料。