Giter VIP home page Giter VIP logo

sinyal's Introduction

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:

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
    .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:

var isAdvertising = beaconBroadcast.isAdvertising()

You can also register 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.

var 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

To broadcast as AltBeacon:

beaconBroadcast
    .setUUID('39ED98FF-2900-441A-802F-9C398FC199D2') //change UUID to yours
    .setMajorId(1) //change major id to yours
    .setMinorId(100) //change minor id to yours
    .start();

To broadcast as iBeacon:

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

Android

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

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, it can't be changed. It's worth to mention that application needs to work in foreground. 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.

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

sinyal's People

Contributors

pszklarska avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.