Git Product home page Git Product logo

rxble's Introduction

中文文档

RxBle

Program Android BLE function with RxJava

SETUP

Make sure your project has been introduced RxJava in build.gradle,like this:

compile 'io.reactivex:rxjava:1.2.3'
compile 'io.reactivex:rxandroid:1.2.1'

And copy RxBle.java to your project.

USEAGE

1.Get the singleton of the RxBle

RxBle rxBle = RxBle.getInstance()

or if you know the target BLE device name such as Test

RxBle rxBle = RxBle.getInstance().setTargetDevice("Test")

2.Open bluetooth by no asking

mRxBle.openBle(this);

3.If you did not use setTargetDevice to set target device name,you should set a listener in RxBle to get a list of devices when scanning,then connect the target device by yourself

rxBle.setScanListener(new RxBle.BleScanListener() {
	@Override
	public void onBleScan(BluetoothDevice bleDevice, int rssi, byte[] scanRecord) {
		// Get list of devices and other information
		if(bledevice.getName().equals("Test")){
			rxBle.connectDevice(bleDevice);
		}
	}
});

4.Communication between Android phone and BLE device

rxBle.sendData(data);
// or send with delay
rxBle.sendData(data,delay);

rxBle.receiveData().subscribe(new Action1<String>() {
	@Override
	public void call(String receiveData) {
		// Data will be received while they sent by BLE device
	}
});

5.Close BLE

rxBle.closeBle();

ADDITIONAL

The best practice is fork and edit it,adapt to your project needs.

FAQ

rxble's People

Contributors

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