Giter Site home page Giter Site logo

bletoolbox's Introduction

BleToolbox

This project is a utility library that implements general Bluetooth LE operations on the Android platform. The library will only be updated sporadically to address bugs or add features as they are needed.

Adding Gradle Dependency

To add the library to your project, first, update the repositories closure to include the MbientLab Ivy Repo in the project's build.gradle file.

repositories {
    ivy {
        url "http://ivyrep.mbientlab.com"
        layout "gradle"
    }
}

Then, add the compile element to the dependencies closure in the module's build.gradle file.

dependencies {
    compile 'com.mbientlab.bletoolbox:scanner:0.2.3'
}

Bluetooth LE Scan

The classes in the scanner package scans for Bluetooth LE devices and displays the results in a ListView. The scanner filters results to only return devices that advertise a valid service UUID and automatically stops scanning after a set duration.

Embedded Fragment

You can embed the fragment in a layout file. The activity containing the fragment will need to implement the BleScannerFragment.ScannerCommunicationBus interface, which is used to configure the scan.

<?xml version="1.0" encoding="utf-8"?>

<!-- Embedding the scanner fragment in a layout -->
<fragment xmlns:tools="http://schemas.android.com/tools" android:id="@+id/fragment"
    android:name="com.mbientlab.bletoolbox.scanner.BleScannerFragment"
    tools:layout="@layout/blescan_device_list" android:layout_width="match_parent"
    android:layout_height="match_parent" />
import android.support.v7.app.AppCompatActivity;

import com.mbientlab.bletoolbox.scanner.BleScannerFragment;
import com.mbientlab.bletoolbox.scanner.BleScannerFragment.*;

public class ExampleEmbeddedScannerActivity extends AppCompatActivityi 
        implements ScannerCommunicationBus {
    @Override
    public void onDeviceSelected(BluetoothDevice device) {
        Toast.makeText(this, String.format(Locale.US, "Selected device: %s", 
                device.getAddress()), Toast.LENGTH_LONG).show();
    }
    
    @Override
    public UUID[] getFilterServiceUuids() {
        ///< Only return MetaWear boards in the scan
        return new UUID[] {UUID.fromString("326a9000-85cb-9195-d9dd-464cfbbae75a")};
    }

    @Override
    public long getScanDuration() {
        ///< Scan for 10000ms (10 seconds)
        return 10000;
    }
}

bletoolbox's People

Contributors

scaryghost avatar

Watchers

 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.