alann-maulana / flutter_beacon

An hybrid iBeacon scanner and transmitter SDK for Flutter Android and iOS.
Apache License 2.0
116 stars 142 forks source link

ranging stream never fires an event #93

Open casvanluijtelaar opened 3 years ago

casvanluijtelaar commented 3 years ago

hey,

I have been testing out this package, But I'm running into an issue where whatever I try, flutterBeacon.ranging will never have a stream update, not with the beacon I'm looking for, not even empty.

this is the beacon I have to test with: image

this is what the implementation looks like:


class Bluetooth implements BluetoothContract {

  final List<Region> _regions = [
    Region(
      identifier: 'IBeacon',
      proximityUUID: 'fda50693-a4e2-4fb1-afcf-c6eb07647825',
    )
  ];

  @override
  Future<bool> initialize() async {
    try {
      return flutterBeacon.initializeAndCheckScanning;
    } on PlatformException {
      throw BluetoothException();
    }
  }

  @override
  Future<List<Beacon>> getBeaconsAsync() async {
    try {
      return (await flutterBeacon.ranging(_regions).first).beacons;
    } catch (e) {
      throw BluetoothException();
    }
  }

  @override
  Stream<List<Beacon>> getBeaconsStream() {
    try {
      return flutterBeacon.ranging(_regions).map((event) => event.beacons);
    } catch (e) {
      throw BluetoothException();
    }
  }

}

I've tested this on the latest stable flutter release on an OnePlus 7 Pro and an LG Nexus 5x. I hope it's something obvious I missed because compared to other beacon packages this one seems to be put together best.

alann-maulana commented 3 years ago

Hi @casvanluijtelaar

Do you already run the example app (and matching the UUID on region)?

casvanluijtelaar commented 3 years ago

I have, same problems. side note, the example android folder hasn't been migrated yet to android embedding v2 Screenshot 2021-05-24 111917 Screenshot_20210524-111903

casvanluijtelaar commented 3 years ago

interesting, just tested the example on a nexus 5x and that did find the beacon correctly. I'll do some investigation why it wouldn't work on a oneplus 7 pro

casvanluijtelaar commented 3 years ago

I can't find out any differences between running on the nexus 5x and the oneplus 7 pro. Other play store beacon apps work fine on the oneplus. but this packages stream will never yield anything. The only thing that stands out is that the oneplus permissions default to "only whilst using the app". Any tips of things I can look into?

casvanluijtelaar commented 3 years ago

I've tested this both on an Oneplus 7 pro and a Samsung Galaxy a41 running android 10. In both cases this package doesn't work with the issues described above. is it possible this package isnt compatible with android 10 yet? @alann-maulana

casvanluijtelaar commented 3 years ago

see this issue? https://stackoverflow.com/questions/58059097/altbeacon-stopped-working-on-android10-and-didenterregion-does-not-get-called-at

casvanluijtelaar commented 3 years ago

the solutions provided on stackoverflow and here https://github.com/alann-maulana/flutter_beacon/issues/67 did not resolve my problems.

alann-maulana commented 3 years ago

I've tested this both on an Oneplus 7 pro and a Samsung Galaxy a41 running android 10. In both cases this package doesn't work with the issues described above. is it possible this package isnt compatible with android 10 yet? @alann-maulana

I have tested it on my Galaxy phones running Android 10 and 11, there is no issue regarding Android version. It's a bit hard to find/borrow a OnePlus phone here. But, I'll look into it again later for device/Android version issue.

Thanks for reporting.

casvanluijtelaar commented 3 years ago

some general information:

Flutter Doctor [√] Flutter (Channel stable, 2.2.0, on Microsoft Windows [Version 10.0.19042.985], locale en-GB) • Flutter version 2.2.0 at D:\Android\flutter • Framework revision b22742018b (3 weeks ago), 2021-05-14 19:12:57 -0700 • Engine revision a9d88a4d18 • Dart version 2.13.0 [√] Android toolchain - develop for Android devices (Android SDK version 29.0.2) • Android SDK at D:\Android\ • Platform android-30, build-tools 29.0.2 • ANDROID_HOME = D:\Android • Java binary at: D:\Android\openjdk\bin\java • Java version OpenJDK Runtime Environment (AdoptOpenJDK)(build 1.8.0_202-b08) • All Android licenses accepted. [√] Chrome - develop for the web • Chrome at C:\Program Files\Google\Chrome\Application\chrome.exe [X] Visual Studio - develop for Windows X Visual Studio not installed; this is necessary for Windows development. Download at https://visualstudio.microsoft.com/downloads/. Please install the "Desktop development with C++" workload, including all of its default components [!] Android Studio (not installed) • Android Studio not found; download from https://developer.android.com/studio/index.html (or visit https://flutter.dev/docs/get-started/install/windows#android-setup for detailed instructions). [√] VS Code (version 1.56.2) • VS Code at C:\Users\casva\AppData\Local\Programs\Microsoft VS Code • Flutter extension version 3.22.0 [√] VS Code, 64-bit edition (version 1.47.3) • VS Code at C:\Program Files\Microsoft VS Code • Flutter extension version 3.22.0 [√] Connected device (4 available) • GM1925 (mobile) • 686db41d • android-arm64 • Android 10 (API 29) • Windows (desktop) • windows • windows-x64 • Microsoft Windows [Version 10.0.19042.985] • Chrome (web) • chrome • web-javascript • Google Chrome 90.0.4430.212 • Edge (web) • edge • web-javascript • Microsoft Edge 91.0.864.37 ! Doctor found issues in 2 categories.
pubspec ```yaml name: leading description: A new Flutter project. version: 1.0.0+1 publish_to: none environment: sdk: ">=2.13.0-0 <3.0.0" dependencies: flutter: sdk: flutter flutter_localizations: sdk: flutter beamer: ^0.12.4 blobs: git: url: https://github.com/ryanheise/flutter_blobs.git ref: nnbd bloc: ^7.0.0 dots_indicator: ^2.0.0 equatable: ^2.0.0 firebase_core: ^1.1.1 firebase_database: ^7.0.0-dev.2 flutter_beacon: git: url: https://github.com/alann-maulana/flutter_beacon.git flutter_bloc: ^7.0.0 flutter_spinkit: ^5.0.0 flutter_svg: ^0.22.0 get_it: ^7.1.3 intl: ^0.17.0 introduction_screen: ^2.1.0 permission_handler: ^8.0.0 platform_device_id: ^1.0.1 smooth_page_indicator: ^0.3.0-nullsafety.0 uuid: ^3.0.4 very_good_analysis: ^2.0.3 vibration: ^1.7.4-nullsafety.0 flutter_beep: ^1.0.0 dev_dependencies: flutter_test: sdk: flutter bloc_test: ^8.0.0 mocktail: ^0.1.2 flutter_launcher_icons: ^0.9.0 flutter_icons: image_path: "assets/icon/icon.png" android: true ios: true adaptive_icon_background: "assets/icon/background.png" # only available for Android 8.0 devices and above adaptive_icon_foreground: "assets/icon/forground.png" # only available for Android 8.0 devices and above flutter_intl: enabled: true flutter: uses-material-design: true generate: true assets: - assets/ - assets/icon/ - assets/icon/icon_dark.png fonts: - family: Karla fonts: - asset: fonts/Karla-Bold.ttf weight: 700 ```
build.gradle ```gradle def localProperties = new Properties() def localPropertiesFile = rootProject.file('local.properties') if (localPropertiesFile.exists()) { localPropertiesFile.withReader('UTF-8') { reader -> localProperties.load(reader) } } def flutterRoot = localProperties.getProperty('flutter.sdk') if (flutterRoot == null) { throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.") } def flutterVersionCode = localProperties.getProperty('flutter.versionCode') if (flutterVersionCode == null) { flutterVersionCode = '1' } def flutterVersionName = localProperties.getProperty('flutter.versionName') if (flutterVersionName == null) { flutterVersionName = '1.0' } apply plugin: 'com.android.application' apply plugin: 'kotlin-android' apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle" apply plugin: 'com.google.gms.google-services' android { compileSdkVersion 30 sourceSets { main.java.srcDirs += 'src/main/kotlin' } defaultConfig { applicationId "com.casvanluijtelaar.leading" minSdkVersion 18 targetSdkVersion 30 versionCode flutterVersionCode.toInteger() versionName flutterVersionName } buildTypes { release { // TODO: Add your own signing config for the release build. // Signing with the debug keys for now, so `flutter run --release` works. signingConfig signingConfigs.debug } } } flutter { source '../..' } dependencies { implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" } ```
android manifest ```xml ```
dariocavada commented 3 years ago

Tested on Mi 9T Android 10 Without any issue.

casvanluijtelaar commented 3 years ago

The only thing I can think of is when asked for Bluetooth permissions both the oneplus and the galaxy only gave the permissions option "only whilst using the app", I see in the source that the "restricted permissions are only for IOS. is there no android equivalent?

dariocavada commented 2 years ago

The only thing I can think of is when asked for Bluetooth permissions both the oneplus and the galaxy only gave the permissions option "only whilst using the app", I see in the source that the "restricted permissions are only for IOS. is there no android equivalent?

Android 10 has new rules for localization permissions:

https://altbeacon.github.io/android-beacon-library/

For target SDK version 29+ (Android 10, 11) is necessary to add manually ACCESS_FINE_LOCATION

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>

and if you want also background scanning:

<uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" />

In the following pull request I've ported the example to the embedding v2 and null safety:

https://github.com/alann-maulana/flutter_beacon/pull/99