"BLE Peripheral Central Example is a sample that utilizes the flutter_ble_peripheral_central and permission_handler"
Home | BLE Central | BLE Peripheral |
---|---|---|
- flutter_ble_peripheral_central
$ flutter pub add flutter_ble_peripheral_central
or
dependencies:
flutter_ble_peripheral_central: ^0.0.5
- permisson_handler
$ flutter pub add permission_handler
or
dependencies:
permission_handler: ^10.4.5
Android
-
Add permission to your
AndroidManifest.xml
.<uses-permission android:name="android.permission.BLUETOOTH" /> <uses-permission android:name="android.permission.BLUETOOTH_ADMIN" /> <uses-permission android:name="android.permission.BLUETOOTH_SCAN" android:usesPermissionFlags="neverForLocation" /> <uses-permission android:name="android.permission.BLUETOOTH_ADVERTISE" /> <uses-permission android:name="android.permission.BLUETOOTH_CONNECT" /> <uses-feature android:name="android.hardware.bluetooth" android:required="true"/> <uses-feature android:name="android.hardware.bluetooth_le" android:required="true"/> <uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" /> <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
-
Register peripheral service to your
AndroidManifest.xml
.<service android:name="com.novice.flutter_ble_peripheral_central.ble.BlePeripheralService" android:exported="true" android:enabled="true" android:permission="android.permission.BLUETOOTH"> </service>
-
Register central service to your
AndroidManifest.xml
.<service android:name="com.novice.flutter_ble_peripheral_central.ble.BleCentralService" android:exported="true" android:enabled="true" android:permission="android.permission.BLUETOOTH_ADMIN"> <intent-filter> <action android:name="android.bluetooth.adapter.action.STATE_CHANGED" /> </intent-filter> </service>
Ios
-
For iOS it is required you add the following entries to the Info.plist file of your app. It is not allowed to access Core BLuetooth without this.
<key>NSBluetoothAlwaysUsageDescription</key> <string>We use Bluetooth to show basic communication between Central and Peripheral</string> <key>NSBluetoothPeripheralUsageDescription</key> <string>We use Bluetooth to show basic communication between Central and Peripheral</string>
- flutter_ble_peripheral_central plugin: https://pub.dev/packages/flutter_ble_peripheral_central
- permisson_handler plugin: https://pub.dev/packages/permission_handler