- Bletia: Promisified BluetoothGatt wrapper library(including JDeferred)
- RxBletia: RxJava binding APIs for Android's BluetoothGatt
Use Bletia:
dependencies {
// use Bletia
compile 'info.izumin.android:bletia:2.0.0'
}
Use RxBletia:
dependencies {
// use RxBletia
compile 'info.izumin.android:bletia:2.0.0'
compile 'io.reactivex:rxjava:1.0.16'
}
// Pass application context to constructor.
Bletia bletia = new Bletia(context);
// BluetoothDevice device
bletia.connect(device);
// BluetoothGattCharacteristic characteristic
bletia.enableNotification(characteristic, true)
.then(new DoneCallback<BluetoothGattCharacteristic>() {
@Override
public void onDone(BluetoothGattCharacteristic result) {
// Call when the request was successfully.
}
})
.fail(new FailCallback<BletiaException>() {
@OVerride
public void onFail(BletiaException result) {
// Call when the request was failure.
}
});
// BluetoothGattCharacteristic characteristic
bletia.readCharacteristic(characteristic)
.then(new DoneCallback<BluetoothGattCharacteristic>() {
@Override
public void onDone(BluetoothGattCharacteristic result) {
// Call when the request was successfully.
}
})
.fail(new FailCallback<BletiaException>() {
@OVerride
public void onFail(BletiaException result) {
// Call when the request was failure.
}
});
// BluetoothGattCharacteristic characteristic
bletia.writeCharacteristic(characteristic)
.then(new DoneCallback<BluetoothGattCharacteristic>() {
@Override
public void onDone(BluetoothGattCharacteristic result) {
// Call when the request was successfully.
}
})
.fail(new FailCallback<BletiaException>() {
@OVerride
public void onFail(BletiaException result) {
// Call when the request was failure.
}
});
// BluetoothGattDescriptor descriptor
bletia.readDescriptor(descriptor)
.then(new DoneCallback<BluetoothGattDescriptor>() {
@Override
public void onDone(BluetoothGattDescriptor result) {
// Call when the request was successfully.
}
})
.fail(new FailCallback<BletiaException>() {
@OVerride
public void onFail(BletiaException result) {
// Call when the request was failure.
}
});
// BluetoothGattDescriptor descriptor
bletia.writeDescriptor(descriptor)
.then(new DoneCallback<BluetoothGattDescriptor>() {
@Override
public void onDone(BluetoothGattDescriptor result) {
// Call when the request was successfully.
}
})
.fail(new FailCallback<BletiaException>() {
@OVerride
public void onFail(BletiaException result) {
// Call when the request was failure.
}
});
bletia.readRemoteRssi()
.then(new DoneCallback<Integer>() {
@Override
public void onDone(Integer result) {
// Call when the request was successfully.
}
})
.fail(new FailCallback<BletiaException>() {
@OVerride
public void onFail(BletiaException result) {
// Call when the request was failure.
}
});
Copyright 2015 izumin5210
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.