项目作者: qiantao94

项目描述 :
Android BLE develop with RxJava
高级语言: Java
项目地址: git://github.com/qiantao94/RxBle.git
创建时间: 2016-11-25T10:01:51Z
项目社区:https://github.com/qiantao94/RxBle

开源协议:

下载


中文文档

RxBle

Program Android BLE function with RxJava

SETUP

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

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

And copy RxBle.java to your project.

USEAGE

1.Get the singleton of the RxBle

  1. RxBle rxBle = RxBle.getInstance()

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

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

2.Open bluetooth by no asking

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

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

4.Communication between Android phone and BLE device

  1. rxBle.sendData(data);
  2. // or send with delay
  3. rxBle.sendData(data,delay);
  4. rxBle.receiveData().subscribe(new Action1<String>() {
  5. @Override
  6. public void call(String receiveData) {
  7. // Data will be received while they sent by BLE device
  8. }
  9. });

5.Close BLE

  1. rxBle.closeBle();

ADDITIONAL

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

FAQ