Bluetooth Low Energy library for Flutter with support for simulating peripherals

Overview

Frontside Build Status pub package

Flutter BLE library logo

FlutterBleLib

A library for all your Bluetooth Low Energy needs in Flutter. Internally utilises Polidea's MultiPlatformBleAdapter, which runs on RxAndroidBle and RxBluetoothKit.

BLE Simulator

This library supports BLEmulator, the BLE simulator. The simulation allows one to develop without physical smartphone or BLE peripheral and use one's production BLE–related code in automated testing.

Installation

To use this plugin, add flutter_ble_lib as a dependency in your pubspec.yaml file.

Android

Set minSDKVersion in [project]/android/app/build.gradle file to 18.

defaultConfig {
  ...
  minSdkVersion 18
  ...
}

Support for Bluetooth Low Energy has been added in API 18, hence the library requires minSDKVersion to be set to 18. If BLE is not core to your application, you can override it and handle support detection in your code.

Notice: You don't need to add any permissions related to BLE to the AndroidManifest.xml, because they are already declared in the library's native module. However, you still need to request ACCESS_FINE_LOCATION permission at runtime to be able to scan for peripheral. See example's code and example's pubspec.

iOS

Go to [project]/ios directory and run pod install.

Add Privacy - Bluetooth Always Usage Description key to [project]/ios/Runner/Info.plist file.

...
<key>NSBluetoothAlwaysUsageDescription</key>
<string>Your own description of the purpose.</string>
...

Background mode

To support background capabilities add The bluetooth-central Background Execution Mode key to [project]/ios/Runner/Info.plist file.

...
<key>UIBackgroundModes</key>
<array>
  <string>bluetooth-central</string>
</array>
...

Usage

The library is organised around a few base entities, which are:

  • BleManager
  • Peripheral
  • Service
  • Characteristic
  • Descriptor

You have to create an instance BleManager and initialise underlying native resources. Using that instance you then obtain an instance of Peripheral, which can be used to run operations on the corresponding peripheral.

All operations passing the Dart-native bridge are asynchronous, hence all operations in the plugin return either Future or Stream.

For more informations, see REFERENCE.

Notice: this library will not handle any permissions for you. To be able to scan for peripherals on Android you need ACCESS_FINE_LOCATION according to Android Developer Guide.

Initialising

BleManager bleManager = BleManager();
await bleManager.createClient(); //ready to go!
// your peripheral logic
bleManager.destroyClient(); //remember to release native resources when you're done!

Following snippets assume the library has been initialised.

Handling Bluetooth adapter state

enum BluetoothState {
  UNKNOWN,
  UNSUPPORTED,
  UNAUTHORIZED,
  POWERED_ON,
  POWERED_OFF,
  RESETTING,
}


bleManager.enableRadio(); //ANDROID-ONLY turns on BT. NOTE: doesn't check permissions
bleManager.disableRadio() //ANDROID-ONLY turns off BT. NOTE: doesn't check permissions
BluetoothState currentState = await bleManager.bluetoothState();
bleManager.observeBluetoothState().listen((btState) {
  print(btState);
  //do your BT logic, open different screen, etc.
});

Scanning for peripherals

bleManager.startPeripheralScan(
  uuids: [
    "F000AA00-0451-4000-B000-000000000000",
  ],
).listen((scanResult) {
  //Scan one peripheral and stop scanning
  print("Scanned Peripheral ${scanResult.peripheral.name}, RSSI ${scanResult.rssi}");
  bleManager.stopPeripheralScan();
});

The snippet above starts peripheral scan and stops it after receiving first result. It filters the scan results to those that advertise a service with specified UUID.

NOTE: isConnectable and overflowServiceUuids fields of ScanResult are iOS-only and remain null on Android.

Connecting to saved peripheral

You can try to connect to a peripheral with known ID, be it previously scanned UUID on iOS or a MAC address on Android, and avoid the whole scanning operation in your application. To do so, you need to create an instance of Peripheral using:

Peripheral myPeripheral = bleManager.createUnsafePeripheral("< known id >");

Once you have the instance of the peripheral, you may proceed with the connection. But keep in mind that Android may still not find the peripheral without scanning it first.

Connecting to peripheral

First you must obtain a ScanResult from BleManager.startPeripheralScan().

Peripheral peripheral = scanResult.peripheral;
peripheral.observeConnectionState(emitCurrentValue: true, completeOnDisconnect: true)
  .listen((connectionState) {
    print("Peripheral ${scanResult.peripheral.identifier} connection state is $connectionState");
  });
await peripheral.connect();
bool connected = await peripheral.isConnected();
await peripheral.disconnectOrCancelConnection();

The snippet above starts observing the state of the connection to the peripheral, connects to it, checks if it's connected and then disconnects from it.

Transactions

Methods that do not have counterpart with opposite effect and are asynchronous accept String transactionId as an optional argument, to allow the user to cancel such an operation. The Future returned to Dart will then finish with a BleError(BleErrorCode.operationCancelled...), but this will only discard the result of the operation, the operation itself will be executed either way.

For example, if I decided that I no longer want to run discovery on the selected peripheral:

//assuming peripheral is connected
peripheral.discoverAllServicesAndCharacteristics(transactionId: "discovery");
//will return operation cancelled error after calling the below
bleManager.cancelTransaction("discovery");

Each new operation with the same transactionId will cause the previous one to be cancelled with error, if it hasn't finished yet. If transactionId is set to null or it isn't specified at all, the library sets unique integer transactionId to such operation.

NOTE: Do not to set integers as transactionId as they are used by the library.

Obtaining characteristics

To be able to operate on the peripheral, discovery of its services and characteristics must be run first.

//assuming peripheral is connected
await peripheral.discoverAllServicesAndCharacteristics();
List<Service> services = await peripheral.services(); //getting all services
List<Characteristic> characteristics1 = await peripheral.characteristics("F000AA00-0451-4000-B000-000000000000");
List<Characteristic> characteristics2 = await services.firstWhere(
  (service) => service.uuid == "F000AA00-0451-4000-B000-000000000000").characteristics();

//characteristics1 and characteristics2 have the same contents

Objects representing characteristics have a unique identifer, so they point to one specific characteristic, even if there are multiple service/characteristic uuid matches.

Manipulating characteristics

Below are 3 methods of writing to a characteristic, which all result in the same effect given there's only one service with specified UUID and only one characteristic with specified UUID.

peripheral.writeCharacteristic(
  "F000AA00-0451-4000-B000-000000000000",
  "F000AA02-0451-4000-B000-000000000000",
  Uint8List.fromList([0]),
  false); //returns Characteristic to chain operations more easily

service.writeCharacteristic(
  "F000AA02-0451-4000-B000-000000000000",
  Uint8List.fromList([0]),
  false); //returns Characteristic to chain operations more easily

characteristic.write(Uint8List.fromList([0]), false); //returns void

Monitoring or reading a characteristic from Peripheral/Service level return CharacteristicWithValue object, which is Characteristic with additional Uint8List value property.

Descriptor operations

List of descriptors from a single characteristic can be obtained in a similar fashion to a list of characteristics from a single service, either from Peripheral, Service or Characteristic object. Descriptors can be read/written from Peripheral, Service or Characteristic by supplying necessary UUIDs, or from Descriptor object.

Note: to enable monitoring of characteristic you should use characteristic.monitor() or (peripheral/service).monitorCharacteristic() instead of changing the value of the underlying descriptor yourself.

Facilitated by Frontside

Frontside provided architectural advice and financial support for this library on behalf of Resideo.

Maintained by

This library is maintained by Polidea

Contact us

Learn more about Polidea's BLE services.

Maintainers

TBD

License

Copyright 2019 Polidea Sp. z o.o

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

More from Polidea

Check out other Polidea's BLE libraries:

Comments
  • Sometimes startPeripheralScan doesn't return any result

    Sometimes startPeripheralScan doesn't return any result

    Hi! I am using your library for a personal project. The problem I have is that when I try to scan many times, the function startPeripheralScan doesn't return anything, or some devices aren't shown. Here is my code:

      void startScan() {
          _devicesList.clear();
          _devicesSink.add(null);
          _scanSubscription = _bleManager
             .startPeripheralScan(scanMode: ScanMode.balanced, allowDuplicates: false)
             .listen((device) {
                 // exclude duplicated devices
                 for (var d in _devicesList) {
                     if (device.peripheral.identifier == d.peripheral.identifier) return;
                 }
                 _devicesList.add(device);
                _devicesSink.add(_devicesList.sublist(0));
          });
          _timeoutTimer = new Timer(const Duration(seconds: 5), () => stopScan());
       }
    
       // Stop BLE devices scan
      Future<void> stopScan() async {
         _timeoutTimer?.cancel();
         if (_devicesList.length == 0) {
           _devicesSink.add([]);
         }
         await _scanSubscription?.cancel();
         await _bleManager?.stopPeripheralScan();
      }
    
    bug Android 
    opened by fpabl0 24
  • BLE Client: not able to write data into characteristics

    BLE Client: not able to write data into characteristics

    BLE Client is not able to write data into characteristics after receiving first ad-hoc notification. The scenario is the following:

    1. Mobile app(hereafter Client) connects to the BLE device.
    2. The client enables notifications on the device (plugin enables notifications automatically).
    3. Client receives ad-hoc notification
    4. Client writes data to characteristics
    5. Device reads the request data
    6. Device writes the response data to characteristics

    Scenario breaks when the Client tries to write the data to characteristics. The device doesn't receive any data from the Client.

    The problem occurs with a real BLE device and Mobile app running Android OS. Scenario above works with BLE emulator + Android, BLE emulator + iOS, Real Device + iOS.

    Also some info about device:

    • Uses the Generic Attribute Profile (GATT).
    • Based on one Service including only one characteristic.
    • Characteristic supports the following operations
      • Read
      • Write
      • Notification
    bug 
    opened by gurgenDP 24
  • Plugin leaks receivers upon connection attempts

    Plugin leaks receivers upon connection attempts

    Observed on version: 2.2.9

    After leaving the application reconnecting to a gone device for several hours, the app is no longer operational - it is not possible to register any receivers as app hit the limit of 1000 registered ones.

    When it happened once, I later tried to pinpoint the culprit (wasnt't sure if this may be scanning related, or maybe even Wifi portion of the app's functionality) and I reproduced it quickly by repeatedly initiating connections. Snippet from the code handling the connection:

    Log.i(
            'Trying to connect... : ${_peripheral.identifier}, attempt: $retryNum');
        bool connected = false;
        Stopwatch stopwatch = Stopwatch()..start();
        try {final isConnected = await _peripheral.isConnected();
          if (!isConnected) {
            await _peripheral
                .connect(isAutoConnect: autoConnect, refreshGatt: true)
                .timeout(autoConnect ? timeoutAuto : timeoutDirect, onTimeout: () {
              Log.i('Timeout when attempting to connect ${_peripheral.identifier}');
              _peripheral.disconnectOrCancelConnection();
              throw TimeoutException(
                  'Failed to connect ${_peripheral.identifier} on time');
            });
          }
    

    Once 1000 connections were reached, this is what I got:

    09-17 00:25:20.871  4526  4526 I Fimber.i: [BleDeviceBloc._connect]:   Trying to connect... : 00:1D:96:07:C1:1D, attempt: 1000
    09-17 00:25:20.878  4526  4526 D com.polidea.flutter_ble_lib.FlutterBleLibPlugin: on native side observed method: isDeviceConnected
    09-17 00:25:20.895  4526  4878 D RxBle#ClientOperationQueue: FINISHED DisconnectOperation(261771749) in 81 ms
    09-17 00:25:20.918  4526  4526 D com.polidea.flutter_ble_lib.FlutterBleLibPlugin: on native side observed method: connectToDevice
    09-17 00:25:21.165  4526  4526 E MethodChannel#flutter_ble_lib: Failed to handle method call
    09-17 00:25:21.165  4526  4526 E MethodChannel#flutter_ble_lib: rx.exceptions.OnErrorNotImplementedException: Too many receivers, total of 1000, registered for pid: 4526, callerPackage: com.*****
    09-17 00:25:21.165  4526  4526 E MethodChannel#flutter_ble_lib: 	at rx.internal.util.InternalObservableUtils$ErrorNotImplementedAction.call(InternalObservableUtils.java:386)
    09-17 00:25:21.165  4526  4526 E MethodChannel#flutter_ble_lib: 	at rx.internal.util.InternalObservableUtils$ErrorNotImplementedAction.call(InternalObservableUtils.java:383)
    09-17 00:25:21.165  4526  4526 E MethodChannel#flutter_ble_lib: 	at rx.internal.util.ActionSubscriber.onError(ActionSubscriber.java:44)
    09-17 00:25:21.165  4526  4526 E MethodChannel#flutter_ble_lib: 	at rx.observers.SafeSubscriber._onError(SafeSubscriber.java:153)
    09-17 00:25:21.165  4526  4526 E MethodChannel#flutter_ble_lib: 	at rx.observers.SafeSubscriber.onError(SafeSubscriber.java:115)
    09-17 00:25:21.165  4526  4526 E MethodChannel#flutter_ble_lib: 	at rx.internal.operators.NotificationLite.accept(NotificationLite.java:132)
    09-17 00:25:21.165  4526  4526 E MethodChannel#flutter_ble_lib: 	at rx.internal.operators.CachedObservable$ReplayProducer.replay(CachedObservable.java:403)
    09-17 00:25:21.165  4526  4526 E MethodChannel#flutter_ble_lib: 	at rx.internal.operators.CachedObservable$CacheState.dispatch(CachedObservable.java:220)
    09-17 00:25:21.165  4526  4526 E MethodChannel#flutter_ble_lib: 	at rx.internal.operators.CachedObservable$CacheState.onError(CachedObservable.java:201)
    09-17 00:25:21.165  4526  4526 E MethodChannel#flutter_ble_lib: 	at rx.internal.operators.CachedObservable$CacheState$1.onError(CachedObservable.java:175)
    09-17 00:25:21.165  4526  4526 E MethodChannel#flutter_ble_lib: 	at rx.internal.operators.OperatorSingle$ParentSubscriber.onError(OperatorSingle.java:129)
    09-17 00:25:21.165  4526  4526 E MethodChannel#flutter_ble_lib: 	at rx.internal.operators.OperatorTake$1.onError(OperatorTake.java:66)
    09-17 00:25:21.165  4526  4526 E MethodChannel#flutter_ble_lib: 	at rx.internal.operators.OperatorMerge$MergeSubscriber.reportError(OperatorMerge.java:266)
    09-17 00:25:21.165  4526  4526 E MethodChannel#flutter_ble_lib: 	at rx.internal.operators.OperatorMerge$MergeSubscriber.checkTerminate(OperatorMerge.java:818)
    09-17 00:25:21.165  4526  4526 E MethodChannel#flutter_ble_lib: 	at rx.internal.operators.OperatorMerge$MergeSubscriber.emitLoop(OperatorMerge.java:579)
    09-17 00:25:21.165  4526  4526 E MethodChannel#flutter_ble_lib: 	at rx.internal.operators.OperatorMerge$MergeSubscriber.emit(OperatorMerge.java:568)
    09-17 00:25:21.165  4526  4526 E MethodChannel#flutter_ble_lib: 	at rx.internal.operators.OperatorMerge$InnerSubscriber.onError(OperatorMerge.java:855)
    09-17 00:25:21.165  4526  4526 E MethodChannel#flutter_ble_lib: 	at rx.internal.operators.OnSubscribeMap$MapSubscriber.onError(OnSubscribeMap.java:88)
    09-17 00:25:21.165  4526  4526 E MethodChannel#flutter_ble_lib: 	at rx.internal.operators.OnSubscribeFilter$FilterSubscriber.onError(OnSubscribeFilter.java:90)
    09-17 00:25:21.165  4526  4526 E MethodChannel#flutter_ble_lib: 	at rx.observers.SerializedObserver.onError(SerializedObserver.java:152)
    09-17 00:25:21.165  4526  4526 E MethodChannel#flutter_ble_lib: 	at rx.observers.SerializedSubscriber.onError(SerializedSubscriber.java:78)
    09-17 00:25:21.165  4526  4526 E MethodChannel#flutter_ble_lib: 	at rx.internal.operators.OnSubscribeConcatMap$ConcatMapSubscriber.innerError(OnSubscribeConcatMap.java:192)
    09-17 00:25:21.165  4526  4526 E MethodChannel#flutter_ble_lib: 	at rx.internal.operators.OnSubscribeConcatMap$ConcatMapInnerSubscriber.onError(OnSubscribeConcatMap.java:340)
    09-17 00:25:21.165  4526  4526 E MethodChannel#flutter_ble_lib: 	at rx.internal.operators.OnSubscribeMap$MapSubscriber.onError(OnSubscribeMap.java:88)
    09-17 00:25:21.165  4526  4526 E MethodChannel#flutter_ble_lib: 	at rx.Observable.unsafeSubscribe(Observable.java:10334)
    09-17 00:25:21.165  4526  4526 E MethodChannel#flutter_ble_lib: 	at rx.internal.operators.OnSubscribeMap.call(OnSubscribeMap.java:48)
    09-17 00:25:21.165  4526  4526 E MethodChannel#flutter_ble_lib: 	at rx.internal.operators.OnSubscribeMap.call(OnSubscribeMap.java:33)
    09-17 00:25:21.165  4526  4526 E MethodChannel#flutter_ble_lib: 	at rx.Observable.unsafeSubscribe(Observable.java:10327)
    09-17 00:25:21.165  4526  4526 E MethodChannel#flutter_ble_lib: 	at rx.internal.operators.OnSubscribeConcatMap$ConcatMapSubscriber.drain(OnSubscribeConcatMap.java:286)
    09-17 00:25:21.165  4526  4526 E MethodChannel#flutter_ble_lib: 	at rx.internal.operators.OnSubscribeConcatMap$ConcatMapSubscriber.onNext(OnSubscribeConcatMap.java:144)
    09-17 00:25:21.165  4526  4526 E MethodChannel#flutter_ble_lib: 	at rx.internal.operators.OnSubscribeFromArray$FromArrayProducer.slowPath(OnSubscribeFromArray.java:100)
    09-17 00:25:21.165  4526  4526 E MethodChannel#flutter_ble_lib: 	at rx.internal.operators.OnSubscribeFromArray$FromArrayProducer.request(OnSubscribeFromArray.java:63)
    09-17 00:25:21.165  4526  4526 E MethodChannel#flutter_ble_lib: 	at rx.Subscriber.setProducer(Subscriber.java:211)
    09-17 00:25:21.165  4526  4526 E MethodChannel#flutter_ble_lib: 	at rx.internal.operators.OnSubscribeFromArray.call(OnSubscribeFromArray.java:32)
    09-17 00:25:21.165  4526  4526 E MethodChannel#flutter_ble_lib: 	at rx.internal.operators.OnSubscribeFromArray.call(OnSubscribeFromArray.java:24)
    09-17 00:25:21.165  4526  4526 E MethodChannel#flutter_ble_lib: 	at rx.Observable.unsafeSubscribe(Observable.java:10327)
    09-17 00:25:21.165  4526  4526 E MethodChannel#flutter_ble_lib: 	at rx.internal.operators.OnSubscribeConcatMap.call(OnSubscribeConcatMap.java:94)
    09-17 00:25:21.165  4526  4526 E MethodChannel#flutter_ble_lib: 	at rx.internal.operators.OnSubscribeConcatMap.call(OnSubscribeConcatMap.java:42)
    09-17 00:25:21.165  4526  4526 E MethodChannel#flutter_ble_lib: 	at rx.Observable.unsafeSubscribe(Observable.java:10327)
    09-17 00:25:21.165  4526  4526 E MethodChannel#flutter_ble_lib: 	at rx.internal.operators.OnSubscribeFilter.call(OnSubscribeFilter.java:45)
    09-17 00:25:21.165  4526  4526 E MethodChannel#flutter_ble_lib: 	at rx.internal.operators.OnSubscribeFilter.call(OnSubscribeFilter.java:30)
    09-17 00:25:21.165  4526  4526 E MethodChannel#flutter_ble_lib: 	at rx.Observable.unsafeSubscribe(Observable.java:10327)
    09-17 00:25:21.165  4526  4526 E MethodChannel#flutter_ble_lib: 	at rx.internal.operators.OnSubscribeMap.call(OnSubscribeMap.java:48)
    09-17 00:25:21.165  4526  4526 E MethodChannel#flutter_ble_lib: 	at rx.internal.operators.OnSubscribeMap.call(OnSubscribeMap.java:33)
    09-17 00:25:21.165  4526  4526 E MethodChannel#flutter_ble_lib: 	at rx.Observable.unsafeSubscribe(Observable.java:10327)
    09-17 00:25:21.165  4526  4526 E MethodChannel#flutter_ble_lib: 	at rx.internal.operators.OperatorMerge$MergeSubscriber.onNext(OperatorMerge.java:248)
    09-17 00:25:21.219  4526  4526 E MethodChannel#flutter_ble_lib: 	at rx.internal.operators.OperatorMerge$MergeSubscriber.onNext(OperatorMerge.java:148)
    09-17 00:25:21.219  4526  4526 E MethodChannel#flutter_ble_lib: 	at rx.internal.operators.OnSubscribeFromArray$FromArrayProducer.fastPath(OnSubscribeFromArray.java:76)
    09-17 00:25:21.219  4526  4526 E MethodChannel#flutter_ble_lib: 	at rx.internal.operators.OnSubscribeFromArray$FromArrayProducer.request(OnSubscribeFromArray.java:58)
    09-17 00:25:21.219  4526  4526 E MethodChannel#flutter_ble_lib: 	at rx.Subscriber.setProducer(Subscriber.java:211)
    09-17 00:25:21.219  4526  4526 E MethodChannel#flutter_ble_lib: 	at rx.internal.operators.OnSubscribeFromArray.call(OnSubscribeFromArray.java:32)
    09-17 00:25:21.219  4526  4526 E MethodChannel#flutter_ble_lib: 	at rx.internal.operators.OnSubscribeFromArray.call(OnSubscribeFromArray.java:24)
    09-17 00:25:21.219  4526  4526 E MethodChannel#flutter_ble_lib: 	at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:48)
    09-17 00:25:21.219  4526  4526 E MethodChannel#flutter_ble_lib: 	at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:30)
    09-17 00:25:21.219  4526  4526 E MethodChannel#flutter_ble_lib: 	at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:48)
    09-17 00:25:21.219  4526  4526 E MethodChannel#flutter_ble_lib: 	at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:30)
    09-17 00:25:21.219  4526  4526 E MethodChannel#flutter_ble_lib: 	at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:48)
    09-17 00:25:21.219  4526  4526 E MethodChannel#flutter_ble_lib: 	at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:30)
    09-17 00:25:21.219  4526  4526 E MethodChannel#flutter_ble_lib: 	at rx.Observable.unsafeSubscribe(Observable.java:10327)
    09-17 00:25:21.219  4526  4526 E MethodChannel#flutter_ble_lib: 	at rx.internal.operators.CachedObservable$CacheState.connect(CachedObservable.java:183)
    09-17 00:25:21.219  4526  4526 E MethodChannel#flutter_ble_lib: 	at rx.internal.operators.CachedObservable$CachedSubscribe.call(CachedObservable.java:248)
    09-17 00:25:21.219  4526  4526 E MethodChannel#flutter_ble_lib: 	at rx.internal.operators.CachedObservable$CachedSubscribe.call(CachedObservable.java:230)
    09-17 00:25:21.219  4526  4526 E MethodChannel#flutter_ble_lib: 	at rx.Observable.subscribe(Observable.java:10423)
    09-17 00:25:21.219  4526  4526 E MethodChannel#flutter_ble_lib: 	at rx.Observable.subscribe(Observable.java:10390)
    09-17 00:25:21.219  4526  4526 E MethodChannel#flutter_ble_lib: 	at rx.Observable.subscribe(Observable.java:10165)
    09-17 00:25:21.219  4526  4526 E MethodChannel#flutter_ble_lib: 	at com.polidea.rxandroidble.internal.connection.DisconnectionRouter.<init>(DisconnectionRouter.java:70)
    09-17 00:25:21.219  4526  4526 E MethodChannel#flutter_ble_lib: 	at com.polidea.rxandroidble.internal.connection.DisconnectionRouter_Factory.get(DisconnectionRouter_Factory.java:33)
    09-17 00:25:21.219  4526  4526 E MethodChannel#flutter_ble_lib: 	at com.polidea.rxandroidble.internal.connection.DisconnectionRouter_Factory.get(DisconnectionRouter_Factory.java:10)
    09-17 00:25:21.219  4526  4526 E MethodChannel#flutter_ble_lib: 	at bleshadow.dagger.internal.DoubleCheck.get(DoubleCheck.java:47)
    09-17 00:25:21.219  4526  4526 E MethodChannel#flutter_ble_lib: 	at com.polidea.rxandroidble.internal.connection.RxBleGattCallback_Factory.get(RxBleGattCallback_Factory.java:33)
    09-17 00:25:21.219  4526  4526 E MethodChannel#flutter_ble_lib: 	at com.polidea.rxandroidble.internal.connection.RxBleGattCallback_Factory.get(RxBleGattCallback_Factory.java:8)
    09-17 00:25:21.219  4526  4526 E MethodChannel#flutter_ble_lib: 	at bleshadow.dagger.internal.DoubleCheck.get(DoubleCheck.java:47)
    09-17 00:25:21.219  4526  4526 E MethodChannel#flutter_ble_lib: 	at com.polidea.rxandroidble.DaggerClientComponent$DeviceComponentImpl$ConnectionComponentImpl.connectOperation(DaggerClientComponent.java:713)
    09-17 00:25:21.219  4526  4526 E MethodChannel#flutter_ble_lib: 	at com.polidea.rxandroidble.internal.connection.ConnectorImpl$1.call(ConnectorImpl.java:54)
    09-17 00:25:21.219  4526  4526 E MethodChannel#flutter_ble_lib: 	at com.polidea.rxandroidble.internal.connection.ConnectorImpl$1.call(ConnectorImpl.java:38)
    09-17 00:25:21.219  4526  4526 E MethodChannel#flutter_ble_lib: 	at rx.internal.operators.OnSubscribeDefer.call(OnSubscribeDefer.java:46)
    09-17 00:25:21.219  4526  4526 E MethodChannel#flutter_ble_lib: 	at rx.internal.operators.OnSubscribeDefer.call(OnSubscribeDefer.java:35)
    09-17 00:25:21.219  4526  4526 E MethodChannel#flutter_ble_lib: 	at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:48)
    09-17 00:25:21.219  4526  4526 E MethodChannel#flutter_ble_lib: 	at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:30)
    09-17 00:25:21.219  4526  4526 E MethodChannel#flutter_ble_lib: 	at rx.Observable.unsafeSubscribe(Observable.java:10327)
    09-17 00:25:21.219  4526  4526 E MethodChannel#flutter_ble_lib: 	at rx.internal.operators.OnSubscribeDefer.call(OnSubscribeDefer.java:51)
    09-17 00:25:21.219  4526  4526 E MethodChannel#flutter_ble_lib: 	at rx.internal.operators.OnSubscribeDefer.call(OnSubscribeDefer.java:35)
    09-17 00:25:21.219  4526  4526 E MethodChannel#flutter_ble_lib: 	at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:48)
    09-17 00:25:21.219  4526  4526 E MethodChannel#flutter_ble_lib: 	at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:30)
    09-17 00:25:21.219  4526  4526 E MethodChannel#flutter_ble_lib: 	at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:48)
    09-17 00:25:21.219  4526  4526 E MethodChannel#flutter_ble_lib: 	at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:30)
    09-17 00:25:21.219  4526  4526 E MethodChannel#flutter_ble_lib: 	at rx.Observable.unsafeSubscribe(Observable.java:10327)
    09-17 00:25:21.219  4526  4526 E MethodChannel#flutter_ble_lib: 	at rx.internal.operators.OnSubscribeMap.call(OnSubscribeMap.java:48)
    09-17 00:25:21.219  4526  4526 E MethodChannel#flutter_ble_lib: 	at rx.internal.operators.OnSubscribeMap.call(OnSubscribeMap.java:33)
    09-17 00:25:21.219  4526  4526 E MethodChannel#flutter_ble_lib: 	at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:48)
    09-17 00:25:21.219  4526  4526 E MethodChannel#flutter_ble_lib: 	at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:30)
    09-17 00:25:21.219  4526  4526 E MethodChannel#flutter_ble_lib: 	at rx.Observable.subscribe(Observable.java:10423)
    09-17 00:25:21.219  4526  4526 E MethodChannel#flutter_ble_lib: 	at rx.Observable.subscribe(Observable.java:10390)
    09-17 00:25:21.219  4526  4526 E MethodChannel#flutter_ble_lib: 	at rx.Observable.subscribe(Observable.java:10298)
    09-17 00:25:21.219  4526  4526 E MethodChannel#flutter_ble_lib: 	at com.polidea.multiplatformbleadapter.BleModule.safeConnectToDevice(BleModule.java:1364)
    09-17 00:25:21.219  4526  4526 E MethodChannel#flutter_ble_lib: 	at com.polidea.multiplatformbleadapter.BleModule.connectToDevice(BleModule.java:437)
    09-17 00:25:21.298  4526  4526 E MethodChannel#flutter_ble_lib: 	at com.polidea.flutter_ble_lib.delegate.DeviceConnectionDelegate.connectToDevice(DeviceConnectionDelegate.java:106)
    09-17 00:25:21.298  4526  4526 E MethodChannel#flutter_ble_lib: 	at com.polidea.flutter_ble_lib.delegate.DeviceConnectionDelegate.onMethodCall(DeviceConnectionDelegate.java:50)
    09-17 00:25:21.298  4526  4526 E MethodChannel#flutter_ble_lib: 	at com.polidea.flutter_ble_lib.FlutterBleLibPlugin.onMethodCall(FlutterBleLibPlugin.java:98)
    09-17 00:25:21.298  4526  4526 E MethodChannel#flutter_ble_lib: 	at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:230)
    09-17 00:25:21.298  4526  4526 E MethodChannel#flutter_ble_lib: 	at io.flutter.embedding.engine.dart.DartMessenger.handleMessageFromDart(DartMessenger.java:85)
    09-17 00:25:21.298  4526  4526 E MethodChannel#flutter_ble_lib: 	at io.flutter.embedding.engine.FlutterJNI.handlePlatformMessage(FlutterJNI.java:692)
    09-17 00:25:21.298  4526  4526 E MethodChannel#flutter_ble_lib: 	at android.os.MessageQueue.nativePollOnce(Native Method)
    09-17 00:25:21.298  4526  4526 E MethodChannel#flutter_ble_lib: 	at android.os.MessageQueue.next(MessageQueue.java:326)
    09-17 00:25:21.298  4526  4526 E MethodChannel#flutter_ble_lib: 	at android.os.Looper.loop(Looper.java:170)
    09-17 00:25:21.298  4526  4526 E MethodChannel#flutter_ble_lib: 	at android.app.ActivityThread.main(ActivityThread.java:6991)
    09-17 00:25:21.298  4526  4526 E MethodChannel#flutter_ble_lib: 	at java.lang.reflect.Method.invoke(Native Method)
    09-17 00:25:21.298  4526  4526 E MethodChannel#flutter_ble_lib: 	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
    09-17 00:25:21.298  4526  4526 E MethodChannel#flutter_ble_lib: 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:884)
    09-17 00:25:21.298  4526  4526 E MethodChannel#flutter_ble_lib: Caused by: java.lang.IllegalStateException: Too many receivers, total of 1000, registered for pid: 4526, callerPackage: com.motorolasolutions.camera.smartcontrol.debug
    09-17 00:25:21.298  4526  4526 E MethodChannel#flutter_ble_lib: 	at android.os.Parcel.createException(Parcel.java:1958)
    09-17 00:25:21.298  4526  4526 E MethodChannel#flutter_ble_lib: 	at android.os.Parcel.readException(Parcel.java:1918)
    09-17 00:25:21.298  4526  4526 E MethodChannel#flutter_ble_lib: 	at android.os.Parcel.readException(Parcel.java:1868)
    09-17 00:25:21.298  4526  4526 E MethodChannel#flutter_ble_lib: 	at android.app.IActivityManager$Stub$Proxy.registerReceiver(IActivityManager.java:3705)
    09-17 00:25:21.298  4526  4526 E MethodChannel#flutter_ble_lib: 	at android.app.ContextImpl.registerReceiverInternal(ContextImpl.java:1515)
    09-17 00:25:21.298  4526  4526 E MethodChannel#flutter_ble_lib: 	at android.app.ContextImpl.registerReceiver(ContextImpl.java:1476)
    09-17 00:25:21.298  4526  4526 E MethodChannel#flutter_ble_lib: 	at android.app.ContextImpl.registerReceiver(ContextImpl.java:1464)
    09-17 00:25:21.298  4526  4526 E MethodChannel#flutter_ble_lib: 	at android.content.ContextWrapper.registerReceiver(ContextWrapper.java:623)
    09-17 00:25:21.298  4526  4526 E MethodChannel#flutter_ble_lib: 	at com.polidea.rxandroidble.RxBleAdapterStateObservable$1.call(RxBleAdapterStateObservable.java:61)
    09-17 00:25:21.298  4526  4526 E MethodChannel#flutter_ble_lib: 	at com.polidea.rxandroidble.RxBleAdapterStateObservable$1.call(RxBleAdapterStateObservable.java:47)
    09-17 00:25:21.298  4526  4526 E MethodChannel#flutter_ble_lib: 	at rx.internal.operators.OnSubscribeCreate.call(OnSubscribeCreate.java:72)
    09-17 00:25:21.298  4526  4526 E MethodChannel#flutter_ble_lib: 	at rx.internal.operators.OnSubscribeCreate.call(OnSubscribeCreate.java:32)
    09-17 00:25:21.298  4526  4526 E MethodChannel#flutter_ble_lib: 	at rx.Observable.unsafeSubscribe(Observable.java:10327)
    09-17 00:25:21.298  4526  4526 E MethodChannel#flutter_ble_lib: 	... 84 more
    09-17 00:25:21.298  4526  4526 E MethodChannel#flutter_ble_lib: Caused by: android.os.RemoteException: Remote stack trace:
    09-17 00:25:21.298  4526  4526 E MethodChannel#flutter_ble_lib: 	at com.android.server.am.ActivityManagerService.registerReceiver(ActivityManagerService.java:22002)
    09-17 00:25:21.298  4526  4526 E MethodChannel#flutter_ble_lib: 	at android.app.IActivityManager$Stub.onTransact$registerReceiver$(IActivityManager.java:10441)
    09-17 00:25:21.298  4526  4526 E MethodChannel#flutter_ble_lib: 	at android.app.IActivityManager$Stub.onTransact(IActivityManager.java:154)
    09-17 00:25:21.298  4526  4526 E MethodChannel#flutter_ble_lib: 	at com.android.server.am.ActivityManagerService.onTransact(ActivityManagerService.java:3548)
    09-17 00:25:21.298  4526  4526 E MethodChannel#flutter_ble_lib: 	at com.android.server.am.ActivityManagerServiceEx.onTransact(ActivityManagerServiceEx.java:476)
    09-17 00:25:21.298  4526  4526 E MethodChannel#flutter_ble_lib: 
    09-17 00:25:21.313  4526  4526 I Fimber.i: [BleDeviceBloc._connect.<anonymous]:   Timeout when attempting to connect 00:1D:96:07:C1:1D
    

    With a profiler from Android Studio I am indeed able to see that there are things that are not released and clearly point to flutter_ble_lib - or rather rxandroidble

    image image

    Once that exception is hit, subsequent calls to connect method end instantly with the following error:

    BleError (Error code: 203, ATT error code: null, iOS error code: null, Android error code: null, reason: Already connected to device with MAC address 00:1D:96:07:C1:1D, internal message: null, device ID: null, service UUID: null, characteristic UUID: null, descriptor UUID: null)
    

    There doesn't seem to be a way of recovering from this - destroying the client does not help. Only way to resolve that seems to require swiping out the app from the recents application list.

    I noticed an issue about a leak in the rxandroidble but it was related to scanning (https://github.com/Polidea/RxAndroidBle/issues/607) - this one seems to be a bigger issue.

    Any hints are appreciated - this is a huge deal for the app I'm working on.

    bug 
    opened by b055man 23
  • Questions about notifications

    Questions about notifications

    When there is a large amount of data notification, the data will be duplicated and overwritten. I wonder if the platform thread and ui thread are thread safe? There is no such problem when using the rxble library natively on Android.

    opened by huaxiao47 20
  • "writing is not permitted" error on native iOS when writing to the characteristic on iPhone X

    When I try to write [0x01] on iPhone X to the characteristic on a BLE device I got a platform error, which says: "writing is not permitted". It works well on any Android phone. It also works on iPhone 6S (iOS 13.3), but on iPhone X it doesn't. I traced this error up to rejectForFlutterResult method: image

    When debugging in Android studio I catch the following error:

    BleError (Error code: 401, ATT error code: 3, iOS error code: null, Android error code: null, reason: Writing is not permitted.,

    image

    I reproduced the same characteristic write sequence in the Nordic nRF Connect app, and everything worked ok (on the same iPhone X). Do you know why this error occurs?

    P.S. Thanks for this library, it's the most stable BLE library for the Flutter out there yet :)

    opened by t-girniak 13
  • Build failures, iOS

    Build failures, iOS

    I am taking a project that was working with the flutter_blue library and attempting to switch it over to flutter_ble_lib but builds are failing.

    First failure is on pod install, I get: Installing flutter_ble_lib (0.0.1) [!] Pods written in Swift can only be integrated as frameworks; adduse_frameworks!to your Podfile or target to opt into using it. The Swift Pods being used are: RxBluetoothKit, RxSwift, and flutter_ble_lib

    I tried adding add use_frameworks! to the Podfile but that leads to more problems relating to Swift:

    `=== BUILD TARGET RxSwift OF PROJECT Pods WITH CONFIGURATION Debug ===

           Check dependencies
           The “Swift Language Version” (SWIFT_VERSION) build setting must be set to a supported value for targets which use Swift. This setting can be set in the build settings editor.
    

    [ +1 ms] Could not build the precompiled application for the device. [ +2 ms] Error launching application on JSI iPhone X. [ +3 ms] "flutter run" took 8,823ms.

    #0 throwToolExit (package:flutter_tools/src/base/common.dart:28) #1 RunCommand.runCommand (package:flutter_tools/src/commands/run.dart:351) #2 FlutterCommand.verifyThenRunCommand (package:flutter_tools/src/runner/flutter_command.dart:290) #3 FlutterCommand.run (package:flutter_tools/src/runner/flutter_command.dart:228) #4 CommandRunner.runCommand (package:args/command_runner.dart:194) #5 FlutterCommandRunner.runCommand (package:flutter_tools/src/runner/flutter_command_runner.dart:286) #6 CommandRunner.run. (package:args/command_runner.dart:109) #7 new Future.sync (dart:async/future.dart:222) #8 CommandRunner.run (package:args/command_runner.dart:109) #9 FlutterCommandRunner.run (package:flutter_tools/src/runner/flutter_command_runner.dart:166) #10 run. (package:flutter_tools/runner.dart:90) #11 AppContext._run (package:flutter_tools/src/base/context.dart:76) #12 AppContext.runInZone. (package:flutter_tools/src/base/context.dart:66) #13 _rootRun (dart:async/zone.dart:1126) #14 _CustomZone.run (dart:async/zone.dart:1023) #15 runZoned (dart:async/zone.dart:1501) #16 AppContext.runInZone (package:flutter_tools/src/base/context.dart:65) #17 run (package:flutter_tools/runner.dart:61) #18 main (package:flutter_tools/executable.dart:48) #19 main (file:///Users/jackivers/Projects/Flutter/flutter/packages/flutter_tools/bin/flutter_tools.dart:16) #20 _startIsolate. (dart:isolate-patch/dart:isolate/isolate_patch.dart:277) #21 _RawReceivePortImpl._handleMessage (dart:isolate-patch/dart:isolate/isolate_patch.dart:165)`

    Flutter Doctor: `[✓] Flutter (Channel beta, v0.1.5, on Mac OS X 10.13.3 17D102, locale en-US) • Flutter version 0.1.5 at /Users/jackivers/Projects/Flutter/flutter • Framework revision 3ea4d06340 (4 weeks ago), 2018-02-22 11:12:39 -0800 • Engine revision ead227f118 • Dart version 2.0.0-dev.28.0.flutter-0b4f01f759

    [✓] Android toolchain - develop for Android devices (Android SDK 27.0.3) • Android SDK at /Users/jackivers/Library/Android/sdk • Android NDK location not configured (optional; useful for native profiling support) • Platform android-27, build-tools 27.0.3 • Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java • Java version OpenJDK Runtime Environment (build 1.8.0_152-release-915-b08)

    [✓] iOS toolchain - develop for iOS devices (Xcode 9.2) • Xcode at /Applications/Xcode.app/Contents/Developer • Xcode 9.2, Build version 9C40b • ios-deploy 1.9.2 • CocoaPods version 1.4.0

    [✓] Android Studio (version 3.0) • Android Studio at /Applications/Android Studio.app/Contents • Java version OpenJDK Runtime Environment (build 1.8.0_152-release-915-b08)

    [✓] VS Code (version 1.21.1) • VS Code at /Applications/Visual Studio Code.app/Contents • Dart Code extension version 2.10.0

    [✓] Connected devices (1 available) • JSI iPhone X • 7abb1638e5f94117408869c9c5236c5acb0d7f0c • ios • iOS 11.2.6`

    opened by jack4git 13
  • Can not work on iPad and iPhone

    Can not work on iPad and iPhone

    both system is 13.4, iPad sometime can not read and write,and tall bleerro code 205,means disconnect,but I try check bledevice,it still connected。 iPhone can not scan any bledevice,and always BluetoothState.UNKNOWN 。

    opened by hu70258tao 11
  • Support for Descriptors

    Support for Descriptors

    For most of the BLE devices, we need to write/read/notify from their descriptors. As far as I checked, this library does not support this functionality. Is there any work around or plans to support descriptors?

    opened by aytunch 11
  • Compatibility with Dart 2.1.1

    Compatibility with Dart 2.1.1

    Updated the gradle plugin, a few dependencies, modified compile target to android 28, fixed a typo, and resolved the new API issues with protobuf and dart:convert.

    Possibly check over lib\generated\bledata.pb.dart, as it was hastily done.

    opened by bashenk 9
  • startPeripheralScan does not return anything. Debug log shows scan finished in 16ms

    startPeripheralScan does not return anything. Debug log shows scan finished in 16ms

    When starting the peripheral scan I'm expecting my device to be found but this does not happen. Nevertheless, In the end I expect onDone to be called, or onError (especially if i stop the scan) but this does not happen either.

    Debug log seems to show the scan finishes in 16ms, which seems strange. D/RxBle#ClientOperationQueue( 6183): FINISHED ScanOperationApi21(164449828) in 16 ms

    I've tried balanced and lowLatency scanMode's, also the firstMatch callback besides allmatches. Am I missing something? The uuids entered are some of the services the my device lists. Also, bluetooth and location service are both enabled.

        await bleManager.createClient();
        await _checkPermissions();
        bleManager.setLogLevel(LogLevel.debug);
    
    
        Future.delayed(Duration(seconds: 15), () async {
          print("Timeout triggered");
          await bleManager.stopPeripheralScan();
          print("Scan stopped");
        });
    
        await bleManager.startPeripheralScan(
          scanMode: ScanMode.lowLatency,
          callbackType: CallbackType.allMatches,
          uuids: [
             "99db2100-ac2d-11e3-a5e2-0800200c9a66",
            "99db2000-ac2d-11e3-a5e2-0800200c9a66",
             "f000ffc0-0451-4000-b000-000000000000"
          ],
        ).listen((event) {
          print("CHECK");
          print("Found a device: ${event.rssi} ${event.peripheral.name}");
        },
            onError: (Object err) => print("An error occuredd"),
            onDone: () => print("OnDone is called")).asFuture(null);
        print("Done scanning");
    
    
    D/com.polidea.flutter_ble_lib.FlutterBleLibPlugin( 6183): on native side observed method: createClient
    I/flutter ( 6183): Permission was granted for location access
    I/flutter ( 6183): set log level to debug
    D/com.polidea.flutter_ble_lib.FlutterBleLibPlugin( 6183): on native side observed method: setLogLevel
    D/com.polidea.flutter_ble_lib.delegate.LogLevelDelegate( 6183): set log level to: debug
    I/flutter ( 6183): Starting scan
    D/com.polidea.flutter_ble_lib.FlutterBleLibPlugin( 6183): on native side observed method: startDeviceScan
    D/RxBle#ClientOperationQueue( 6183): QUEUED   ScanOperationApi21(164449828)
    D/RxBle#ClientOperationQueue( 6183): STARTED  ScanOperationApi21(164449828)
    I/RxBle#QueueOperation( 6183): Scan operation is requested to start.
    D/BluetoothAdapter( 6183): isLeEnabled(): ON
    D/BluetoothLeScanner( 6183): onScannerRegistered() - status=0 scannerId=13 mScannerId=0
    D/RxBle#ClientOperationQueue( 6183): FINISHED ScanOperationApi21(164449828) in 16 ms
    I/flutter ( 6183): Timeout triggered
    D/com.polidea.flutter_ble_lib.FlutterBleLibPlugin( 6183): on native side observed method: stopDeviceScan
    I/RxBle#CancellableSubscription( 6183): Scan operation is requested to stop.
    D/BluetoothAdapter( 6183): isLeEnabled(): ON
    I/flutter ( 6183): Done scanning
    D/com.polidea.flutter_ble_lib.FlutterBleLibPlugin( 6183): on native side observed method: stopDeviceScan
    I/flutter ( 6183): Transition { currentState: PamSearchInProgress, event: PamSearchStarted, nextState: PamSearchFailure { error: NoSuchMethodError: The method 'retainWhere' was called on null.
    I/flutter ( 6183): Receiver: null
    I/flutter ( 6183): Tried calling: retainWhere(Closure: (ScanResult) => bool) } }
    I/flutter ( 6183): Scan stopped
    
    opened by RickVM 8
  • How to define a discoverable service?

    How to define a discoverable service?

    It is not clear how do define a service, which would be discoverable on the remote end's side upon connection.

    I am developing an app that connects to another BLE device which implements the "Wireless UART" service. I am able to connect and transmit but not receive messages from it. I assume it is because my app is not recognisable to the remote app as one which implements the "Wireless UART" service. I know as a fact that the remote device expects which ever it connects to to "have" this service; It even initiates a disconnect if the service is missing.

    opened by SharonU 8
  • iOS 16 gets Error code: 402 when reading data from monitorCharacteristic()

    iOS 16 gets Error code: 402 when reading data from monitorCharacteristic()

    [VERBOSE-2:dart_vm_initializer.cc(41)] Unhandled Exception: BleError (Error code: 402, ATT error code: 2, iOS error code: null, Android error code: null, reason: Reading is not permitted., internal message: null, device ID: 48E32FDC-BC25-0B46-AC03-549FD00B26B8, service UUID: ce060030-43e5-11e4-916c-0800200c9a66, characteristic UUID: ce060039-43e5-11e4-916c-0800200c9a66, descriptor UUID: null)

    Android works with no errors but iOS throws this when data is received in the listen() from monitorCharacteristic steam.

    opened by Aldaniee 3
  • iOS not scanning peripherals when scanning again immediately

    iOS not scanning peripherals when scanning again immediately

    There's already an open issue related to this (#580) but in my case it worked fine 1st time and then it's not scanning anything after that. It works fine on Android. My flow is create client, scan, connect, disconnect, destroy client. Then when I create a client again and start scanning it doesn't scan any peripheral. What am I missing?

    On Flutter Stable 3.0.5

    UPDATE: So I followed the example workflow and never destroy the client, I just stop scanning and disconnect from the device. Now I am able to scan every time successfully. Is this the right way to do it as I'm not destroying the client after I'm done scanning and pairing? If I destroy the client and then create a new one I am not able to perform any operations using the bleManager, not just scanning.

    opened by iamongit 0
  • Android 12 error: could not find callback wrapper

    Android 12 error: could not find callback wrapper

    Hi everyone I am working on the Bluetooth connection and I have some problems with the new Android version. Most Android phones work perfectly except for some Samsung phones (S21, S21 +). Does anyone know about these issues? Please give me some help.

    I have tried to add permission but it still has no luck.

    minSdkVersion 21
    targetSdkVersion 31
    
        <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.ACCESS_COARSE_LOCATION"/>
    
    I/flutter (23844): DeviceService - waiting for power on - BluetoothState.POWERED_ON
    I/flutter (23844): DevicesScanningBloc - start scan
    D/com.polidea.flutter_ble_lib.FlutterBleLibPlugin(23844): on native side observed method: startDeviceScan
    I/BluetoothAdapter(23844): STATE_ON
    I/BluetoothAdapter(23844): STATE_ON
    I/BluetoothAdapter(23844): STATE_ON
    I/BluetoothAdapter(23844): STATE_ON
    D/BluetoothLeScanner(23844): Start Scan with callback
    I/BluetoothAdapter(23844): STATE_ON
    I/BluetoothAdapter(23844): STATE_ON
    D/BluetoothLeScanner(23844): could not find callback wrapper
    
    opened by lpc-nz 1
  • Ble error on connecting multiple devcies

    Ble error on connecting multiple devcies

    When connecting multiple devices and running a Realtime monitoring and a file transfer service for one of the devices connected a error occurs for that device and automatically disconnects. This only happens in Android phones. Is this due to the library being deprecated as it uses a deprecated version of the android embedding or possibly an error in the code that has been developed. The biggest issue is that this only occurs in android phones and never in IOS. Any information is much appreciated, I can provide more information.

    opened by va-ji 0
  • update example

    update example

    I've had a problem with flutter pub get with the old version of rxdart, updating the version solved it, this may be a common problem so I think it should be up to date.

    and I've cleaned some warnings

    opened by adnanjpg 1
  • establishSession method call below error

    establishSession method call below error

    scanBle Ble Method code change uuids: []

    
      Stream<ScanResult> scanBle() {
        stopScanBle();
        return _bleManager.startPeripheralScan(
            uuids: [], //[TransportBLE.PROV_BLE_SERVICE],
            scanMode: ScanMode.balanced,
            allowDuplicates: true);
      }
    
    

    Error code: 302, ATT error code: null, iOS error code: null, Android error code: null, reason: null, internal message: null, device ID: null, service UUID: 021a9004-0382-4aea-bff4-6b3f1c5adfb4, characteristic UUID: null, descriptor UUID: null

    Screenshot 2022-01-21 at 12 58 44 PM

    Not received wifi list

    Error

    Screenshot 2022-01-21 at 1 02 07 PM

    opened by MurtuzaSrashtaSoft 0
Releases(v2.3.2)
  • v2.3.2(Feb 3, 2021)

  • v3.0.0-beta(Dec 11, 2020)

    3.0.0-beta

    • BREAKING Migrate Android implementation to RxAndroidBle2 This might require the user to implement a global error handler https://github.com/ReactiveX/RxJava/wiki/What's-different-in-2.0#error-handling See more: https://github.com/Polidea/RxAndroidBle/wiki/FAQ:-UndeliverableException
    Source code(tar.gz)
    Source code(zip)
  • v2.3.1(Nov 19, 2020)

    2.3.1

    • Fix connection timeout on iOS
    • Fix emitting current connection state on iOS
    • Update MBA to 0.1.7:
      • Fix lack of disconnection event on iOS when connection fails to be established
      • Fix not all errors being passed through onError callbacks on Android (thanks, @eliaslecomte)
    Source code(tar.gz)
    Source code(zip)
  • v2.3.0(Aug 25, 2020)

    2.3.0

    • add BleManager.createUnsafePeripheral() to allow for connecting to known peripheral without launching scan first NOTE: this change will not work with BLEmulator below 1.2.0
    Source code(tar.gz)
    Source code(zip)
  • v2.2.9(Jul 24, 2020)

  • v2.2.8(Jul 17, 2020)

  • v2.2.7(Jul 17, 2020)

  • v2.2.6(Jul 16, 2020)

  • v2.2.5(Jun 10, 2020)

    2.2.5

    • add missing handling of destroyClient call on iOS
    • fix race condition in ConnectionStateStreamHandler (thanks, @cbreezier!)
    • fix issue with picking incorrect characteristic on Android when there are multiple characteristics with the same UUID on the peripheral
    • update pubspec format to properly display supported platforms
    • fix messages in IllegalStateExceptions on Android
    Source code(tar.gz)
    Source code(zip)
  • v2.2.4(May 7, 2020)

    • Fix issue where withResponse argument was always true when writing to a characteristic on iOS
    • Remove unnecessary file that was interfering with analyzer
    Source code(tar.gz)
    Source code(zip)
  • v2.2.3(Mar 10, 2020)

  • v2.2.2(Feb 27, 2020)

  • v2.2.1(Feb 21, 2020)

    • Hide private APIs
    • Add setup instructions to README
    • Add missing descriptor operations information to README
    • Moved permission_handler dependency to its place in example
    Source code(tar.gz)
    Source code(zip)
  • v2.2.0(Feb 17, 2020)

    • NEW operations on descriptors
    • BREAKING FOR BLEMULATOR BLEmulator versions lower than 1.1.0 are not supported from this release
    • Support for AndroidX
    • Support for Swift 5
    • Lower iOS deployment target to 8.0
    Source code(tar.gz)
    Source code(zip)
  • v2.0.1(Dec 13, 2019)

Owner
intent
We are an international digital product design & development studio. Programming languages: Java, JavaScript, Objective-C, Swift, Python.
intent
null 5 Nov 21, 2022
I have created app to connect printer with bluetooth. And I already fix library bugs

flutter_bluetooth_printer A new Flutter application. Getting Started This project is a starting point for a Flutter application. A few resources to ge

Bounphone KOSADA 1 May 11, 2022
Bluetooth plugin for Flutter

Introduction FlutterBlue is a bluetooth plugin for Flutter, a new app SDK to help developers build modern multi-platform apps. Alpha version This libr

Paul DeMarco 2.1k Nov 26, 2022
Using Bluetooth plugin in Flutter (flutter_bluetooth_serial)

Flutter Bluetooth NOTE: This is the updated version of the app (using flutter_bluetooth_serial 0.2.2). This version has much fewer bugs and provides a

Souvik Biswas 179 Nov 22, 2022
A Flutter Template to communicate with an esp32 over bluetooth

Flutter Esp32 Bluetooth Template Changes in android/ [1 if you take the code to an other project, 2 still nessesarely]: Change minSdkVersion from 16 t

0x4d/Martin Loretz 20 Oct 14, 2022
This flutter app will help you to connect to Bluetooth Devices (like, HC-05)

Flutter Bluetooth NOTE: This is the updated version of the app (using flutter_bluetooth_serial 0.2.2). This version has much fewer bugs and provides a

Riyad Al-Ali 1 Jun 5, 2022
Flutter basic implementation for Classical Bluetooth (only RFCOMM for now)

flutter_bluetooth_serial Flutter basic implementation for Classical Bluetooth (only RFCOMM for now). Features The first goal of this project, started

null 1 Nov 7, 2022
A project to get data from a fitbit device using bluetooth

Flutter 2 Boilerplate (version 1.3.0) A boilerplate project created in flutter. Boilerplate supports both web and mobile. VSCode is recommended in thi

Vajira Att 0 Dec 16, 2021
EI Blue - Edge Impulse Data Capture Over Bluetooth

EI Blue - Edge Impulse Data Capture Over Bluetooth Purpose of this project is to enable embedded engineers to collect data from bluetooth enabled micr

Mithun Das 2 Apr 16, 2022
Flutter library that handles BLE operations for multiple devices.

Flutter reactive BLE library Flutter library that handles BLE operations for multiple devices. Usage The reactive BLE lib supports the following: BLE

Philips Hue 439 Nov 23, 2022
Flutter beacons plugin for Android and iOS.

Beacons Flutter plugin to work with beacons. Supports Android API 16+ and iOS 8+. Features: Automatic permission management Ranging Monitoring (includ

Loup 76 Mar 10, 2022
Flutter NFC reader plugin for iOS and Android

Flutter NFC Reader & Writer A new flutter plugin to help developers looking to use internal hardware inside iOS or Android devices for reading and wri

Matteo Crippa 317 Nov 15, 2022
A Flutter plugin for turning your device into a beacon.

Beacon Broadcast plugin for Flutter A Flutter plugin for turning your device into a beacon. Usage To use this plugin, add beacon_broadcast as a depend

Paulina Szklarska 74 Nov 4, 2022
Flutter plugin for accessing the NFC features on Android and iOS.

nfc_manager Flutter plugin for accessing the NFC features on Android and iOS. Note: This plugin depends on NFCTagReaderSession (requires iOS 13.0 or l

null 120 Nov 19, 2022
Ready for Building Production-Ready Healthcare/ Doctor Consult Android and iOS app UI using Flutter.

Production-Ready Doctor Consultant App - Flutter UI Watch it on YouTube Packages we are using: flutter_svg: link Complete Source code (Patreon) In thi

Abu Anwar 203 Nov 10, 2022
ESC/POS (thermal, receipt) printing for Flutter & Dart (Android/iOS)

esc_pos_bluetooth The library allows to print receipts using a Bluetooth printer. For WiFi/Ethernet printers, use esc_pos_printer library. TODO (PRs a

Andrey 171 Nov 21, 2022
FlutterBleLib - A library for all your Bluetooth Low Energy needs in Flutter.

FlutterBleLib A library for all your Bluetooth Low Energy needs in Flutter. Internally utilises Polidea's MultiPlatformBleAdapter, which runs on RxAnd

null 4 Jun 10, 2022
Flutter blue plus - Flutter plugin for connecting and communicationg with Bluetooth Low Energy devices, on Android and iOS

Introduction FlutterBluePlus is a bluetooth plugin for Flutter, a new app SDK to

null 126 Nov 19, 2022
Gas station flutter - Mobile app created for learning purpose simulating a gas station prices comparizon

gas_station A new Flutter project. Getting Started This project is a starting po

Victor Alves 0 Jan 25, 2022
Low-level link (text, URLs, emails) parsing library in Dart

linkify Low-level link (text, URLs, emails) parsing library in Dart. Required Dart >=2.12 (has null-safety support). Flutter library. Pub - API Docs -

Charles C 60 Nov 4, 2022