![效果图](https://github.com/Jasonchenlijian/FastBle/raw/master/preview/fastble_poster.png)
Thanks to the logo designed by [anharismail](https://github.com/anharismail)
# FastBle
Android Bluetooth Low Energy
- Filtering, scanning, linking, reading, writing, notification subscription and cancellation in a simple way.
- Supports acquiring signal strength and setting the maximum transmission unit.
- Support custom scan rules
- Support multi device connections
- Support reconnection
- Support configuration timeout for conncet or operation
### Preview
![Preview_1](https://github.com/Jasonchenlijian/FastBle/raw/master/preview/new_1.png)
![Preview_2](https://github.com/Jasonchenlijian/FastBle/raw/master/preview/new_2.png)
![Preview_3](https://github.com/Jasonchenlijian/FastBle/raw/master/preview/new_3.png)
![Preview_4](https://github.com/Jasonchenlijian/FastBle/raw/master/preview/new_4.png)
### APK
If you want to quickly preview all the functions, you can download APK as a test tool directly.
[FastBLE.apk](https://github.com/Jasonchenlijian/FastBle/raw/master/FastBLE.apk)
### Gradle
- Setp1: Add it in your root build.gradle at the end of repositories
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
- Step2: Add the dependency
dependencies {
implementation 'com.github.Jasonchenlijian:FastBle:2.4.0'
}
### Jar
[FastBLE-2.4.0.jar](https://github.com/Jasonchenlijian/FastBle/raw/master/FastBLE-2.4.0.jar)
## Wiki
[中文文档](https://github.com/Jasonchenlijian/FastBle/wiki)
[Android BLE开发详解和FastBle源码解析](https://www.jianshu.com/p/795bb0a08beb)
## Usage
- #### Init
BleManager.getInstance().init(getApplication());
- #### Determine whether the current Android system supports BLE
boolean isSupportBle()
- #### Open or close Bluetooth
void enableBluetooth()
void disableBluetooth()
- #### Initialization configuration
BleManager.getInstance()
.enableLog(true)
.setReConnectCount(1, 5000)
.setSplitWriteNum(20)
.setConnectOverTime(10000)
.setOperateTimeout(5000);
- #### Configuration scan rules
`void initScanRule(BleScanRuleConfig scanRuleConfig)`
BleScanRuleConfig scanRuleConfig = new BleScanRuleConfig.Builder()
.setServiceUuids(serviceUuids)
.setDeviceName(true, names)
.setDeviceMac(mac)
.setAutoConnect(isAutoConnect)
.setScanTimeOut(10000)
.build();
BleManager.getInstance().initScanRule(scanRuleConfig);
Tips:
- Before scanning the device, scan rules can be configured to filter out the equipment matching the program.
- What is not configured is the default parameter
- #### Scan
`void scan(BleScanCallback callback)`
BleManager.getInstance().scan(new BleScanCallback() {
@Override
public void onScanStarted(boolean success) {
}
@Override
public void onScanning(BleDevice bleDevice) {
}
@Override
public void onScanFinished(List<BleDevice> scanResultList) {
}
});
Tips:
- The scanning and filtering process is carried out in the worker thread, so it will not affect the UI operation of the main thread. Eventually, every callback result will return to the main thread.。
- #### Connect with device
`BluetoothGatt connect(BleDevice bleDevice, BleGattCallback bleGattCallback)`
BleManager.getInstance().connect(bleDevice, new BleGattCallback() {
@Override
public void onStartConnect() {
}
@Override
public void onConnectFail(BleDevice bleDevice, BleException exception) {
}
@Override
public void onConnectSuccess(BleDevice bleDevice, BluetoothGatt gatt, int status) {
}
@Override
public void onDisConnected(boolean isActiveDisConnected, BleDevice bleDevice, BluetoothGatt gatt, int status) {
}
});
Tips:
- On some types of phones, connectGatt must be effective on the main thread. It is very recommended that the connection process be placed in the main thread.
- After connection failure, reconnect: the framework contains reconnection mechanism after connection failure, which can configure reconnection times and intervals. Of course, you can also call the `connect` method in `onConnectFail` callback automatically.
- The connection is disconnected and reconnected: you can call the `connect` method again in the `onDisConnected` callback method.
- In order to ensure the success rate of reconnection, it is recommended to reconnect after a period of interval.
- When some models fail, they will be unable to scan devices for a short time. They can be connected directly through device objects or devices MAC without scanning.
- #### Connect with Mac
`BluetoothGatt connect(String mac, BleGattCallback bleGattCallback)`
BleManager.getInstance().connect(mac, new BleGattCallback() {
@Override
public void onStartConnect() {
}
@Override
public void onConnectFail(BleDevice bleDevice, BleException exception) {
}
@Override
public void onConnectSuccess(BleDevice bleDevice, BluetoothGatt gatt, int status) {
}
@Override
public void onDisConnected(boolean isActiveDisConnected, BleDevice bleDevice, BluetoothGatt gatt, int status) {
}
});
Tips:
- This method can attempt to connect directly to the BLE device around the Mac without scanning.
- In many usage scenarios, I suggest that APP save the Mac of the user's customary device, then use this method to connect, which will greatly improve the connection efficiency.
- #### Scan and connect
After scanning the first equipment that meets the scanning rules, it will stop scanning and connect to the device.
`void scanAndConnect(BleScanAndConnectCallback callback)`
BleManager.getInstance().scanAndConnect(new BleScanAndConnectCallback() {
@Override
public void onScanStarted(boolean success) {
}
@Override
public void onScanFinished(BleDevice scanResult) {
}
@Override
public void onStartConnect() {
}
@Override
public void onConnectFail(BleDevice bleDevice,BleException exception) {
}
@Override
public void onConnectSuccess(BleDevice bleDevice, BluetoothGatt gatt, int status) {
}
@Override
public void onDisConnected(boolean isActiveDisConnected, BleDevice device, BluetoothGatt gatt, int status) {
}
});
- #### Cancel scan
`void cancelScan()`
BleManager.getInstance().cancelScan();
Tips:
- If this method is called, if it is still in the scan state, it will end immediately, and callback the `onScanFinished` method.
- #### Notify
`void notify(BleDevice bleDevice,
String uuid_service,
String uuid_notify,
BleNotifyCallback callback)`
`void notify(BleDevice bleDevice,
String uuid_service,
String uuid_notify,
boolean useCharacteristicDescriptor,
BleNotifyCallback callback)`
BleManager.getInstance().notify(
bleDevice,
uuid_service,
uuid_characteristic_notify,
new BleNotifyCallback() {
@Override
public void onNotifySuccess() {
}
没有合适的资源?快使用搜索试试~ 我知道了~
FastBle.zip
共105个文件
java:42个
png:22个
xml:21个
需积分: 5 0 下载量 121 浏览量
2023-08-18
09:42:32
上传
评论
收藏 3.78MB ZIP 举报
温馨提示
FastBle
资源推荐
资源详情
资源评论
收起资源包目录
FastBle.zip (105个子文件)
FastBLE-2.4.0.aar 60KB
FastBLE.apk 1.39MB
gradlew.bat 2KB
ble0.gif 6.54MB
.gitignore 45B
build.gradle 969B
build.gradle 927B
build.gradle 342B
config.gradle 271B
settings.gradle 30B
gradlew 5KB
FastBLE-2.3.4.jar 76KB
gradle-wrapper.jar 52KB
BleManager.java 28KB
BleBluetooth.java 26KB
BleConnector.java 25KB
CharacteristicOperationFragment.java 18KB
MainActivity.java 16KB
CharacteristicListFragment.java 8KB
BleScanPresenter.java 7KB
DeviceAdapter.java 6KB
SplitWriter.java 6KB
OperationActivity.java 5KB
BleScanner.java 5KB
MultipleBluetoothController.java 5KB
ServiceListFragment.java 5KB
HexUtil.java 4KB
BleDevice.java 3KB
BleScanRuleConfig.java 2KB
BleMsg.java 2KB
BleException.java 1KB
ConnectException.java 1KB
ObserverManager.java 990B
BleLruHashMap.java 899B
BleGattCallback.java 743B
BleLog.java 661B
GattException.java 627B
BleConnectStateParameter.java 495B
BleBaseCallback.java 435B
ApplicationTest.java 348B
BleIndicateCallback.java 333B
BleNotifyCallback.java 329B
BleScanAndConnectCallback.java 303B
BleScanCallback.java 302B
BleWriteCallback.java 301B
BleMtuChangedCallback.java 273B
BleReadCallback.java 270B
BleRssiCallback.java 265B
BleScanState.java 248B
Observable.java 230B
BleScanPresenterImp.java 202B
TimeoutException.java 198B
OtherException.java 192B
Observer.java 149B
BleWriteState.java 116B
ic_wx.jpg 39KB
LICENSE 11KB
README.md 17KB
ble5.png 89KB
ble3.png 70KB
ble1.png 56KB
ble4.png 51KB
fastble_poster.png 44KB
donations.png 39KB
new_4.png 39KB
new_2.png 38KB
new_1.png 34KB
ble2.png 33KB
new_3.png 26KB
ic_launcher.png 13KB
ic_launcher.png 8KB
ic_launcher.png 5KB
ic_launcher.png 3KB
ic_scan.png 3KB
ic_loading.png 3KB
ic_rssi.png 3KB
ic_blue_remote.png 2KB
ic_launcher.png 2KB
ic_blue_connected.png 1KB
ic_enter.png 1001B
proguard-rules.pro 657B
proguard-rules.pro 657B
gradle.properties 778B
gradle-wrapper.properties 230B
activity_main.xml 4KB
adapter_device.xml 4KB
strings.xml 2KB
strings.xml 2KB
strings.xml 2KB
adapter_service.xml 1KB
activity_user.xml 1KB
adapter_characteristic.xml 1KB
fragment_service_list.xml 1KB
layout_characteric_operation_et.xml 1KB
AndroidManifest.xml 1KB
layout_characteric_operation.xml 981B
activity_operation.xml 718B
layout_characteric_operation_button.xml 632B
fragment_characteric_list.xml 626B
fragment_characteric_operation.xml 439B
共 105 条
- 1
- 2
资源评论
hello_中年人
- 粉丝: 7
- 资源: 324
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功