Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

5.0.3 version does not can't scan BLE Beacons devices on Android 12+ #664

Closed
fufylev opened this issue Dec 25, 2022 · 14 comments
Closed

5.0.3 version does not can't scan BLE Beacons devices on Android 12+ #664

fufylev opened this issue Dec 25, 2022 · 14 comments

Comments

@fufylev
Copy link

fufylev commented Dec 25, 2022

When use a flutter_reactive_ble scanner does not see any Beacon devices on Android 12+
I tried to scan for devices - scanner does not detect any BLE Beacons devices on Android 12+, while it perfectly detects all of BLE Beacon devices on Android 11 and lower.

To Reproduce
Steps to reproduce the behavior:

  1. Clone repo
  2. Run flutter pub get and flutter packages pub run build_runner build --delete-conflicting-outputs in folders: example, packages/flutter_reactive_ble, packages/reactive_ble_mobile, packages/reactive_ble_platform_interface.
  3. Run an app on Android 12+
  4. Scan for devices near the Beacon sensors.

Expected behavior
While scanning all BLE Beacons devices must be detected

Smartphone

  • Device: [SM M127F - Samsung Galaxy M12 32GB]
  • OS: [Android 12]

Peripheral device

  • Vendor, model: [AprilBrother, model number 2.0.4]
  • Does it run a custom firmware / software: no, firm revision 4.0.8

Additional context
To start an app from example I had to fix some bugs

  1. Added an import
    import 'dart:typed_data';
    to files:
packages/reactive_ble_mobile/lib/src/converter/protobuf_converter.dart
packages/reactive_ble_mobile/test/reactive_ble_platform_test.dart
  1. Modify an AndroidManifest file like this, otherwise an app doesn't even start

Screenshot 2022-12-25 at 13 20 29

@fufylev fufylev changed the title 5.0.3 version does not can't scaan 5.0.3 version does not can't scan BLE Beacons devices Dec 25, 2022
@fufylev fufylev changed the title 5.0.3 version does not can't scan BLE Beacons devices 5.0.3 version does not can't scan BLE Beacons devices on Android 12+ Dec 25, 2022
@watsmyname
Copy link

It works in my Android 12, not using code from example folder though.

@PlayCulture
Copy link

PlayCulture commented Jan 2, 2023

I have observed the following, running flutter_reactive_ble:

  • Android 11 phone can detect AltBeacons and iBeacons and other bluetooth devices
  • Android 13 phone can detect AltBeacons but not iBeacons, and can still detect other bluetooth devices

I've also seen the same behaviour with other beacon-sensing packages for flutter, such as flutter_beacon and beacon_broadcast. Is there a possibility this is a permission-realted issue?

@JulianAtTroido
Copy link

Based on this Stackoverflow it seems that the underlaying Android library RxAndroidBle which flutter_reactive_ble uses defines the scanForDevices without on empty ScanFilter: see here line 70.

@PlayCulture
Copy link

Thanks for the thoughts and references Julian. I'm not using any ScanFilter currently, but still only seeing iBeacons on my Android 11 phone. Are you suggesting that we need to add something iBeacon-specific into the withServices field?

btStream = flutterReactiveBle.scanForDevices(withServices: [], scanMode: ScanMode.balanced).distinct().listen((device) {}

@JulianAtTroido
Copy link

JulianAtTroido commented Jan 6, 2023

I am not suggesting anything 😅.
We are ourself looking into the iBeacon issue, as we found out that only the inclusion of this package in the pubspec.yamlfile breaks the iBeacon Scanning part of our own plugin. (Without calling the flutter_reactive_ble plugin anywhere in dart code)

As we have only tested on Android 13 so far, it seems that the flutter_reactive_ble, by only beeing registered as a plugin (without being called!) swallows all the iBeacons from the Android system.
Why that is we are not sure, but the above mentioned Stackoverflow post was the only hint we could find so far.

If you have any idea, we would be happy to resolve this problem, too 😄

I don't think the withServices needs any classifier, but based on the stack answer it seems that by only accepting the list and calling the .setServiceUuid(service) method iBeacons might be blocked.
(But this idea does not explain why it works under Android 11 for you)

@PlayCulture
Copy link

Thanks again Julian - I'm looking forward to testing. It sounds like "flutter_reactive_ble breaking iBeacons for everything" might deserve its own issue thread? I'm curious what could have changed from Android 11 to cause an issue like this.

@JulianAtTroido
Copy link

We just fixed our "problem" by using the solution from this #566 (comment). 🎉
It is also outlined in the readme of this library.
Keep in mind, that you might need to remove tools:targetApi="s" as compared to the readme example.

Please tell me if that also resolved your problem.

@PlayCulture
Copy link

Thanks again for the advice, much appreciated. Unfortunately the only thing that has worked for me is to completely remove reactive_ble. Now other ble packages can sense iBeacons again, so i'm up and running. Damn!

@fufylev
Copy link
Author

fufylev commented Jan 25, 2023

We just fixed our "problem" by using the solution from this #566 (comment). 🎉 It is also outlined in the readme of this library. Keep in mind, that you might need to remove tools:targetApi="s" as compared to the readme example.

Please tell me if that also resolved your problem.

It did not help me. I still can't detect iBeacons on Android 12

@fufylev
Copy link
Author

fufylev commented Jan 25, 2023

Thanks again for the advice, much appreciated. Unfortunately the only thing that has worked for me is to completely remove reactive_ble. Now other ble packages can sense iBeacons again, so i'm up and running. Damn!

Which package you've chosen?

@PlayCulture
Copy link

PlayCulture commented Jan 25, 2023

I'm using flutter_beacon - As of today we have broadcasting and sensing working on Android 11 and 13, as well as iOS. Hope that helps!

Top tip that might help you: iOS handles bluetooth permission weirdly, so you don't want to explicitly request it, just go ahead and try to use bluetooth and it will automatically request permission. For Android you should request first, then use

@fufylev
Copy link
Author

fufylev commented Jan 25, 2023

I'm using flutter_beacon - As of today we have broadcasting and sensing working on Android 11 and 13, as well as iOS. Hope that helps!

Top tip that might help you: iOS handles bluetooth permission weirdly, so you don't want to explicitly request it, just go ahead and try to use bluetooth and it will automatically request permission. For Android you should request first, then use

Thanks for reply.
I've spent several hours on this flutter_beacon but still not able to scan any devices. App crashes in 2 seconds.
Which region do you apply. Would be very appreciated if you provide a simple code example that works (fufylev@gmail.com)

@PlayCulture
Copy link

So with iBeacons you have to know the UUID you are looking for before you scan, you can't just scan for anything that's around. Here's a snipet from our project:

String Uuid = "00000000-0000-0000-0000-000000000000"; // Put your known UUID here
String Identifier = "com.playculture"; // Replace with your project ID
String Layout = "m:2-3=0215,i:4-19,i:20-21,i:22-23,p:24-24"; // iBeacon, must be this value
int ManufacturerId = 0x004c; // Reserved when using iBeacon, must be this value

For AltBeacon you can do all sorts of things, but iOS won't be able to transmit anything other than iBeacon.

Hope that helps!

@dkozenkov
Copy link

We just fixed our "problem" by using the solution from this #566 (comment). 🎉 It is also outlined in the readme of this library. Keep in mind, that you might need to remove tools:targetApi="s" as compared to the readme example.

Please tell me if that also resolved your problem.

Thank you for your link. The problem is actually solved by making the specified changes to the file AndroidManifest.xml, and I used the string 'tools:targetApi="s"'. It is important to note that to start scanning, you need to request the necessary permissions directly in the application. In my case, I requested the following permissions: locationWhenInUse, bluetoothScan, bluetoothConnect. For this, I used the 'permission_handler' package from pub.dev.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants