A Flutter plugin for turning your device into a beacon.

Overview

Beacon Broadcast plugin for Flutter

Awesome Flutter Pub

A Flutter plugin for turning your device into a beacon.

Usage

To use this plugin, add beacon_broadcast as a dependency in your pubspec.yaml file and import:

import 'package:beacon_broadcast/beacon_broadcast.dart';

Now you can create BeaconBroadcast object and start using it:

Important note: For Android app, user needs to turn on Bluetooth on the device first.

BeaconBroadcast beaconBroadcast = BeaconBroadcast();

In the simplest case, to start advertising just set your UUID, major and minor id and call start():

beaconBroadcast
    .setUUID('39ED98FF-2900-441A-802F-9C398FC199D2')
    .setMajorId(1)
    .setMinorId(100)
    .start();

You can also customize your beacon before starting:

beaconBroadcast
    .setUUID('39ED98FF-2900-441A-802F-9C398FC199D2')
    .setMajorId(1)
    .setMinorId(100)
    .setTransmissionPower(-59) //optional
    .setAdvertiseMode(AdvertiseMode.lowPower) //Android-only, optional
    .setIdentifier('com.example.myDeviceRegion') //iOS-only, optional
    .setLayout('s:0-1=feaa,m:2-2=10,p:3-3:-41,i:4-21v') //Android-only, optional
    .setManufacturerId(0x001D) //Android-only, optional
    .start();

You can check what's current state of your beacon:

bool isAdvertising = await beaconBroadcast.isAdvertising()

You can also listen for changes in beacon advertising state:

beaconBroadcast.getAdvertisingStateChange().listen((isAdvertising) {
    // Now you know if beacon is advertising
});

Before advertising, you may want to check if your device supports transmitting as a beacon. You may do it using checkTransmissionSupported() method.

BeaconStatus transmissionSupportStatus = await beaconBroadcast.checkTransmissionSupported();
switch (transmissionSupportStatus) {
  case BeaconStatus.SUPPORTED:
    // You're good to go, you can advertise as a beacon
    break;
  case BeaconStatus.NOT_SUPPORTED_MIN_SDK:
    // Your Android system version is too low (min. is 21)
    break;
  case BeaconStatus.NOT_SUPPORTED_BLE:
    // Your device doesn't support BLE
    break;
  case BeaconStatus.NOT_SUPPORTED_CANNOT_GET_ADVERTISER:
    // Either your chipset or driver is incompatible
    break;
}

If you want to stop advertising, just call stop():

beaconBroadcast.stop();

Examples

Simple usage example can be found in the example folder.

Changing beacon layouts

By default beacons layout is set according to the manufacturer (see section Beacon manufacturers). You can change that layout to imitate transmitting as a different kind of beacon.

Note: For iOS layout is set to iBeacon and can't be changed.

To broadcast as AltBeacon:

beaconBroadcast
    .setUUID('39ED98FF-2900-441A-802F-9C398FC199D2')
    .setMajorId(1)
    .setMinorId(100)
    .start();

To broadcast as iBeacon:

beaconBroadcast
    .setUUID('39ED98FF-2900-441A-802F-9C398FC199D2')
    .setMajorId(1)
    .setMinorId(100)
    .setLayout('m:2-3=0215,i:4-19,i:20-21,i:22-23,p:24-24')
    .setManufacturerId(0x004c)
    .start();

Adding extra data

If you have your beacon layout set accordingly, you're allowed to transmit some extra data. Depending on the layout it's usually up to 2 bytes.

For AltBeacon it's 1 byte of additional data (source). For iBeacon (iOS) there's no option to send extra data, as the iBeacon layout doesn't support it.

To add extra data using AltBeacon layout:

beaconBroadcast
    .setUUID('39ED98FF-2900-441A-802F-9C398FC199D2')
    .setMajorId(1)
    .setMinorId(100)
    .setExtraData([123])
    .start();

Beacon manufacturers

Android

Android beacon will advertise as the AltBeacon manufactured by RadiusNetwork. You can change it with setLayout() and setManufacturerId() methods.

iOS

For iOS, beacon will advertise as an iBeacon (by Apple), it can't be changed.

Transmitting in the background

Android

Due to background execution limits introduced in Android 8 beacons transmission in the background is limited. Based on the AltBeacon documentation it's around 10 minutes, after that time transmission will stop. Current version of plugin doesn't support Foreground Services to exceed this limitation.

iOS

For iOS, application doesn't work in the background. According to the CoreLocation documentation:

Important

After advertising your app as a beacon, your app must continue running in the foreground to broadcast the needed Bluetooth signals. If the user quits the app, the system stops advertising the device as a peripheral over Bluetooth.In addition, since iOS 13, a privacy usage description is required to use Bluetooth. Otherwise, the app will experience a runtime crash. To remedy this, add the following lines to your Info.plist

<key>NSBluetoothAlwaysUsageDescription</key>
<string>(Reason bluetooth is used)</string>

For deployment targets earlier than iOS 13, add these additional lines to your Info.plist

<key>NSBluetoothPeripheralUsageDescription</key>
<string>(Reason bluetooth is used)</string>

About

This plugin uses Android Beacon Library for Android and CoreLocation for iOS.

Todo

There are still few things left to implement:

  • Adding option for checking for Android device support programmatically
  • Adding option to set layout and manufacturer for Android implementation
  • Handle turning on BLE before transmitting
  • Add Foreground Service to exceed background limitations on Android 8+
Comments
  • Where are the data fields?

    Where are the data fields?

    Hello!

    Looking into the Android Beacon Library I can see that there is a "setDataFields" method but beacon_broadcast doesn't exposes it to us.

    image

    Being so, how can I set the data my beacon will broacast, like an url or a simple string?

    Thank you for your time and effort onto this library!

    opened by shinayser 9
  • The library does not work on Android 12

    The library does not work on Android 12

    Any solution to this error, it won't let me install the application in android 12

    Failure [INSTALL_PARSE_FAILED_MANIFEST_MALFORMED: Failed parse during installPackageLI: /data/app/vmdl1325317315.tmp/base.apk (at Binary XML file line #90): org.altbeacon.beacon.startup.StartupBroadcastReceiver: Targeting S+ (version 31 and above) requires that an explicit value for android:exported be defined when intent filters are present]

    @pszklarska

    Thank you for the development of the library.

    opened by byblady 7
  • Could not broadcast on Android

    Could not broadcast on Android

    I used this lib to broadcast and used other libs to scan beacons. I tested on real devices:

    • On iOS: I can see other ios beacons.
    • On Android: I can ios beacons.

    I used another android app (install from PlayStore) to broadcast and my app can see that device. That means there is something wrong on the broadcast from my app.

    BeaconBroadcast beaconBroadcast = BeaconBroadcast();
    
    if (Platform.isIOS) {
          beaconBroadcast
            .setUUID('XXXX-...')
            .setMajorId(2)
            .setMinorId(102)
            .start();
        }else{
          beaconBroadcast
            .setUUID('XXXX-...')
            .setMajorId(5)
            .setMinorId(105)
            .start();
        }
    
    opened by tamnguyen-kbtg 7
  • AltBeacon Library Update

    AltBeacon Library Update

    • Updated AltBeacon Library from 2.17.1 to 2.19.3, to support android apps targeting SDK 31 and above Apps Targeting S+ (version 31 and above) requires that an explicit value for android:exported Closes #31

    • Updated Kotlin Version to 1.6.10

    • Updated CHANGELOG & pubspec version to 0.3.1

    • Updated Example App to run on the latest Flutter SDK and changed app's target SDK to 31

    • All Tests Passed

    • Tested on Physical Devices

      • Samsung A10s (Android 11)
      • Nokia 8.1 (Android 11)
    opened by praveen-gm 5
  • Noob Question - Broadcasting Eddystone UID

    Noob Question - Broadcasting Eddystone UID

    Heyo,

    I have to advertise as Eddystone UID. Is this possible using this library? (Please excuse the noob question. I just starting reading into this beacon topic yesterday)

    Regards, Lars

    opened by jagsus 2
  • Function .setMajor() isn't working iOS Platform

    Function .setMajor() isn't working iOS Platform

    Ok so I configure my environment with no problems whatsoever, there's a bug when I'm trying to configure the Major before starting the broadcast in iOS Platform.

    beaconBroadcast
                .setUUID(uuid)
                .setIdentifier('com.example.com')
                .setMinorId(0)
                //.setMajorId(100)
                .setTransmissionPower(-59)
                .start();
    

    So when I uncommented the line with the function major the app never get running I can't get any feedback from the app.

    Edit:

    if (Platform.isIOS){
            beaconBroadcast
                .setUUID('$uuid')
                .setMajorId(0) 
                .setMinorId(0) 
                .setIdentifier('$uuid')
                .setTransmissionPower(-59)
                .start();
            debugPrint('iOS');
          } 
    

    just close it after updates and review the code I didn't notice more issues I have a hard time back then but now is fully working. this is the code I have right now.

    opened by LutfiGarzon 2
  • made gradlew file executable for everybody

    made gradlew file executable for everybody

    I experimented with beacon_broadcast a bit recently. After some flutter/gradle updates I couldn't run "flutter build apk" anymore. The flutter log pointed me to the problem: the gradlew file seems to have wrong file permissions. I'm really not sure how/why it worked before, but making the file executable solved my issues. Maybe you could consider merging this PR

    opened by dknaus 2
  • Issue with building for iOS

    Issue with building for iOS

    Hi 👋

    First of all thank you for the effort taken into this library! I have an use-case in wanted to try it out immediately, sadly I have errors in a clean flutter project, running on my iOS device. I think it has to do with the project setup it's using objective-c instead of swift.

    Running pod install...
    CocoaPods' output:
    ↳
          Preparing
    
        Analyzing dependencies
    
        Inspecting targets to integrate
          Using `ARCHS` setting to build architectures of target `Pods-Runner`: (``)
    
        Fetching external sources
        -> Fetching podspec for `Flutter` from `.symlinks/flutter/ios`
        -> Fetching podspec for `beacon_broadcast` from `.symlinks/plugins/beacon_broadcast/ios`
    
        Resolving dependencies of `Podfile`
    
        Comparing resolved specification to the sandbox manifest
          A Flutter
          A beacon_broadcast
    
        Downloading dependencies
    
        -> Installing Flutter (1.0.0)
    
        -> Installing beacon_broadcast (0.0.1)
          - Running pre install hooks
        [!] Unable to determine Swift version for the following pods:
    
        - `beacon_broadcast` does not specify a Swift version and none of the targets (`Runner`) integrating it have the `SWIFT_VERSION` attribute set. Please contact the author or set the `SWIFT_VERSION` attribute in at least one of the targets that integrate this pod.
    
        /usr/local/Cellar/cocoapods/1.6.1/libexec/gems/cocoapods-1.6.1/lib/cocoapods/installer/xcode/target_validator.rb:115:in `verify_swift_pods_swift_version'
        /usr/local/Cellar/cocoapods/1.6.1/libexec/gems/cocoapods-1.6.1/lib/cocoapods/installer/xcode/target_validator.rb:37:in `validate!'
        /usr/local/Cellar/cocoapods/1.6.1/libexec/gems/cocoapods-1.6.1/lib/cocoapods/installer.rb:459:in `validate_targets'
        /usr/local/Cellar/cocoapods/1.6.1/libexec/gems/cocoapods-1.6.1/lib/cocoapods/installer.rb:138:in `install!'
        /usr/local/Cellar/cocoapods/1.6.1/libexec/gems/cocoapods-1.6.1/lib/cocoapods/command/install.rb:48:in `run'
        /usr/local/Cellar/cocoapods/1.6.1/libexec/gems/claide-1.0.2/lib/claide/command.rb:334:in `run'
        /usr/local/Cellar/cocoapods/1.6.1/libexec/gems/cocoapods-1.6.1/lib/cocoapods/command.rb:52:in `run'
        /usr/local/Cellar/cocoapods/1.6.1/libexec/gems/cocoapods-1.6.1/bin/pod:55:in `<top (required)>'
        /usr/local/Cellar/cocoapods/1.6.1/libexec/bin/pod:22:in `load'
        /usr/local/Cellar/cocoapods/1.6.1/libexec/bin/pod:22:in `<main>'
    
    Error output from CocoaPods:
    ↳
    
        [!] `<PBXGroup UUID=`97C146E51CF9000F007C117D`>` attempted to initialize an object with an unknown UUID. `CF3B75C9A7D2FA2A4C99F110` for attribute: `children`. This can be the result of a merge and  the unknown UUID is being discarded.
    
        [!] Automatically assigning platform `ios` with version `8.0` on target `Runner` because no platform was specified. Please specify a platform for this target in your Podfile. See `https://guides.cocoapods.org/syntax/podfile.html#platform`.
    
    Finished with error: Error running pod install
    
    
    opened by patrickdronk 2
  • V2 Embeeding issue

    V2 Embeeding issue

    The plugin beacon_broadcast uses a deprecated version of the Android embedding. To avoid unexpected runtime failures, or future build failures, try to see if this plugin supports the Android V2 embedding. Otherwise, consider removing it since a future release of Flutter will remove these deprecated APIs. If you are plugin author, take a look at the docs for migrating the plugin to the V2 embedding: https://flutter.dev/go/android-plugin-migration

    opened by LutfiGarzon 1
  • Eddystone layouts broadcast.

    Eddystone layouts broadcast.

    BeaconBroadcast()
    .setUUID('0000feaa-0000-1000-8000-00805f9b34fb')
    .setMajorId(1)
    .setMinorId(100)
    .setTransmissionPower(-59) //optional
    .setAdvertiseMode(AdvertiseMode.lowPower) //Android-only, optional
    .setLayout(BeaconBroadcast.ALTBEACON_LAYOUT)
    .setManufacturerId(0x00E0) //Android-only, optional
    .start();
    

    When i try to broadcast eddystone url by setting layout EDDYSTONE_URL_LAYOUT app produces error PlatformException (PlatformException(error, Beacon has 3 identifiers but format requires 2, null))

    While I have tried by unsetting MinorId then library throws exception of casting null to int not allowed.

    Any solution/suggestion will be appreciated. Thanks.

    opened by theasifiqbal 1
  • Added additional params

    Added additional params

    Hi! In my case was necessary change advertise mode from default (ADVERTISE_MODE_LOW_POWER) to more efficiency (ADVERTISE MODE LOW_LATENCY). Unfortunately there is no params or method to set it. I added params, that allowed it. Please, review it.

    opened by kiokumicu 1
  • Identifier seems to be required on iOS

    Identifier seems to be required on iOS

    Running the sample app on iOS resulted in a crash, I added setIdentifier and there is no more crash.

    The logs for the crash :

    flutter: Supported
    Could not cast value of type 'NSNull' (0x1da937500) to 'NSString' (0x1da934ca0).
    * thread #1, queue = 'com.apple.main-thread', stop reason = signal SIGABRT
        frame #0: 0x00000001b7f04b98 libsystem_kernel.dylib`__pthread_kill + 8
    libsystem_kernel.dylib`__pthread_kill:
    ->  0x1b7f04b98 <+8>:  b.lo   0x1b7f04bb8               ; <+40>
        0x1b7f04b9c <+12>: pacibsp
        0x1b7f04ba0 <+16>: stp    x29, x30, [sp, #-0x10]!
        0x1b7f04ba4 <+20>: mov    x29, sp
    Target 0: (Runner) stopped.
    
    opened by glemartret 1
  • Android - X

    Android - X

    !Please understand that I am not good at English so I am using a translator.

    IOS = O Android = X

    IOS works fine, but not Android

    android

    If you look at the logs on Android, it says that it is normally transmitting BLE signals, but it does not transmit actual BLE signals.

    -Test Device = Galaxy S7, Galaxy Note9

    Running with the sample file provided by the BLE library developer Github results in the same phenomenon

    question 
    opened by Hitbee-dev 4
  • iOS - [CoreBluetooth] XPC Connection Invalid

    iOS - [CoreBluetooth] XPC Connection Invalid

    Greetings,

    First of all, thank you for providing this library for the general public. Once the app has launched, I'm getting an error in the Xcode console that says: "[CoreBluetooth] XPC connection invalid"

    Below is what I'm using hardware/software wise:

    • macOS Catalina v10.15.4
    • Xcode v11.5
    • Flutter v1.17.1
    • iPhone 6S Plus -- iOS v13.5

    I also made sure to add the NSBluetoothAlwaysUsageDescription and NSBluetoothPeripheralUsageDescription permissions to the info.plist file.

    bug 
    opened by luigi741 3
  • Error Handling in Dart

    Error Handling in Dart

    Hello and thank you for making this library. I currently have an issue where is an error occurs, the error is not passed onto Dart (i.e. can't catch it using try, catchError, etc), but appears on the console:

    Performing hot reload...
    Syncing files to device blah-blah...
    Reloaded 1 of 512 libraries in 809ms.
    D/BeaconParser( 7318): Parsing beacon layout: blah-blah-blah
    D/BluetoothAdapter( 7318): isLeEnabled(): ON
    D/BluetoothAdapter( 7318): isLeEnabled(): ON
    E/BeaconTransmitter( 7318): Advertisement start failed, code: 2
    

    Just passing the error code as a return variable (instead of Future<void>, then await/then) would be fine for my use case, but it if you have the time to do it, please change the code so programs can catch the error.

    Here is a Stack Overflow question about the same issue.

    Thank you in advance.

    bug 
    opened by nyiyui 0
Releases(v0.3.1)
  • v0.3.1(Jun 4, 2022)

    What's Changed

    • Fixed static analysis issues and CI workflow by @pszklarska in https://github.com/pszklarska/beacon_broadcast/pull/34
    • AltBeacon Library Update by @praveen-gm in https://github.com/pszklarska/beacon_broadcast/pull/33

    Full Changelog: https://github.com/pszklarska/beacon_broadcast/compare/v0.3.0...v0.3.1

    Source code(tar.gz)
    Source code(zip)
  • v0.3.0(Nov 21, 2021)

    What's Changed

    • Nullsafety & Flutter 2.5.3 by @praveen-gm in https://github.com/pszklarska/beacon_broadcast/pull/29
    • Add GitHub Actions to build, test and publish by @pszklarska in https://github.com/pszklarska/beacon_broadcast/pull/30

    New Contributors

    • @praveen-gm made their first contribution in https://github.com/pszklarska/beacon_broadcast/pull/29

    Full Changelog: https://github.com/pszklarska/beacon_broadcast/compare/v0.2.3...v0.3.0

    Source code(tar.gz)
    Source code(zip)
Owner
Paulina Szklarska
Flutter GDE / Android & Flutter Developer / cat owner / travel enthusiast
Paulina Szklarska
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 Sep 12, 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 312 Sep 15, 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 115 Aug 30, 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 177 Sep 4, 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 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 417 Sep 23, 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 193 Sep 15, 2022
Bluetooth Low Energy library for Flutter with support for simulating peripherals

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

intent 499 Sep 9, 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 163 Sep 13, 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 19 Sep 3, 2022
null 4 Aug 3, 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 0 Apr 13, 2022
A simple Flutter package that makes turning a FAB into a text field easy.

flutter_text_field_fab A simple Flutter widget that makes turning a FAB into a text field easy.

Haefele Software 4 Jan 18, 2022
Android-Toolbox is a desktop app which enables the user to access android device features which are not accessible directly from the mobile device

Android-Toolbox is a desktop app which enables the user to access android device features which are not accessible directly from the mobile device. One of Android-Toolbox's special feature is to transfer files at the highest speed using ADB push and pull bypassing a lot of Android API overheads.

Sashank Visweshwaran 20 Sep 3, 2022
SSH no ports provides ssh to a remote Linux device with out that device having any ports open

Ssh! No ports ssh no ports provides a way to ssh to a remote linux host/device without that device having any open ports (not even 22) on external int

The Atsign Foundation 217 Sep 22, 2022
A Flutter widget that forces the device rotates into the set of orientations the application interface can be displayed in.

A Flutter widget that forces the device rotates into the set of orientations the application interface can be displayed in. Features Force device keep

De Men 1 Nov 30, 2021
Flutter-Shared-Preference - The goal is to learn how to use the shared preferences plugin to save important pieces of information to your device.

Recipe Finder The goal is to learn how to use the shared preferences plugin to save important pieces of information to your device. Final App UI Resou

Ashirbad Swain 1 Jan 1, 2022
A responsive scaffold widget that adjusts to your device size, for your flutter mobile and web apps.

scaffold_responsive A responsive scaffold widget that adjusts to your device size, for your flutter mobile and web apps. Check out the Live demo here

Tushar Sadhwani 10 Dec 16, 2021