[![](https://jitpack.io/v/com.gitee.HarlanSong/walle-ble.svg)](https://jitpack.io/#com.gitee.HarlanSong/walle-ble)
walle-ble is Android Bluetooth Low Energy tool.
[中文文档](https://github.com/HarlanSong/walle-ble/blob/master/README_CN.md)
## Function & Features
* Simplify bluetooth connection and operation.
* Scanning equipment function.
* Supports multiple bluetooth solutions.
* Support for command queue execution.
## Bluetooth low energy flow
![img](https://gitee.com/HarlanSong/walle-ble/raw/master/images/BluetoothLowEnergyFlow.png)
## Configuration
**repositories**
```groovy
maven { url "https://jitpack.io" }
```
**Gradle**
```groovy
implementation 'com.gitee.HarlanSong:walle-ble:1.0.30'
```
**Add permission**
```xml
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
```
## Document
### Scanning page
![img](https://gitee.com/HarlanSong/walle-ble/raw/master/images/ScanDevice.jpg)
```java
String[] scanFilterName = {"NB-202"};
Intent intent = new Intent(this, DeviceScanActivity.class);
intent.putExtra("showSignalStrength", false);
intent.putExtra("scanFilterName", scanFilterName);
startActivityForResult(intent, REQUEST_BIND_DEVICE);
```
* REQUEST_BIND_DEVICE Custom callback constants(int)*
* scanFilterName Filter Name
* showSignalStrength Whether to display signal strength value
### Device selection successful
```java
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == RESULT_OK && REQUEST_BIND_DEVICE == requestCode) {
String name = data.getStringExtra("name");
String macAddress = data.getStringExtra("macAddress");
Toast.makeText(this, "name:" + name + " macAddress:" + macAddress, Toast.LENGTH_LONG).show();
BleUtil.connectDevice(this, name, macAddress);
}
}
```
### Custom scan page.
**Start scan**
```java
BleUtil.startScan(final Context context)
```
**Stop scan**
```java
BleUtil.stopScan(Context context)
```
**Add results to listen for broadcasts**
```java
IntentFilter intentFilter = new IntentFilter();
intentFilter.addAction(WalleBleService.ACTION_SCAN_RESULT);
intentFilter.addAction(WalleBleService.ACTION_SCAN_TIMEOUT);
registerReceiver(scanResultBroadcastReceiver, intentFilter);
```
**Example results**
```java
BroadcastReceiver scanResultBroadcastReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
if (WalleBleService.ACTION_SCAN_RESULT.equals(intent.getAction())) {
BluetoothDeviceEntity device = new BluetoothDeviceEntity();
device.setRssi(intent.getIntExtra("rssi", 0));
device.setName(intent.getStringExtra("name"));
device.setAddress(intent.getStringExtra("address"));
addBluetoothDeviceEntity(device);
} else if (WalleBleService.ACTION_SCAN_TIMEOUT.equals(intent.getAction())) {
mScanning = false;
refreshOptionStatus();
}
}
};
```
### Disconnect
```java
BleUtil.disConnect(this);
```
### Listen for device connection status
```java
private BroadcastReceiver bleReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if (WalleBleService.ACTION_CONNECTED_SUCCESS.equals(action)) {
} else if (WalleBleService.ACTION_GATT_DISCONNECTED.equals(action)) {
} else if (WalleBleService.ACTION_DEVICE_RESULT.equals(action)) {
String uuid = intent.getStringExtra("uuid");
ArrayList<Integer> dataArray = intent.getIntegerArrayListExtra("data");
byte[] srcData = intent.getByteArrayExtra("srcData");
}
}
};
```
* ACTION_CONNECTED_SUCCESS Connection successful
* ACTION_GATT_DISCONNECTED Disconnected
* ACTION_DEVICE_RESULT The device has data to return, 'uuid' is the return characteristic value uuid; 'data' is the parsed array. 'srcData' is the original data;
### Write the content
```java
BleUtil.broadcastWriteBle(Context context, String notifyServiceUUID,
String notifyCharacteristicUUID, String writeServiceUUID,
String writeCharacteristicUUID, byte[] bytes);
```
### Read the content
```java
BleUtil.readBle(Context context, String serviceUUID, String characteristicUUID);
```
### Determine whether the device is connected
```java
getConnectStatus(Context context)
```
**Result**
* BleUtil.CONNECT_STATUS_NOT_CONNECTED Not connected
* BleUtil.CONNECT_STATUS_CONNECTING Connecting
* BleUtil.CONNECT_STATUS_SUCCESS Connected
* BleUtil.CONNECT_STATUS_FAIL Connection fail
### MAC address of connected device
```java
BleUtil.bleAddress
```
### Connected device name
```JAVA
BleUtil.bleName
```
### BleUtil Other Use
```java
/**
* Connecting device
* @param context
* @param address MAC address
*/
void connectDevice(Context context,String address)
/**
* Connecting device
* @param context
* @param address MAC address
* @param autoConnect Auto connect(Default false)
*/
void connectDevice(Context context, String address, boolean autoConnect)
/**
* Disconnect
* @param context
*/
void disConnect(Context context)
/**
* Read content
* @param context
* @param serviceUUID
* @param characteristicUUID
*/
void readBle(Context context, String serviceUUID, String characteristicUUID)
/**
* Write content
* @param context
* @param notifyServiceUUID
* @param notifyCharacteristicUUID
* @param writeServiceUUID
* @param writeCharacteristicUUID
* @param bytes
*/
void broadcastWriteBle(Context context, String notifyServiceUUID,
String notifyCharacteristicUUID, String writeServiceUUID,
String writeCharacteristicUUID, byte[] bytes)
/**
* Write content
*
* @param context
* @param notifyServiceUUID
* @param notifyCharacteristicUUID
* @param writeServiceUUID
* @param writeCharacteristicUUID
* @param bytes Content
* @param segmentation Whether to subcontract the send,true will packet the send with up to 20 bytes
*/
void broadcastWriteBle(Context context, String notifyServiceUUID,
String notifyCharacteristicUUID, String writeServiceUUID,
String writeCharacteristicUUID, byte[] bytes, boolean segmentation)
/**
* Write content
*
* @param context
* @param notifyServiceUUID
* @param notifyCharacteristicUUID
* @param writeServiceUUID
* @param writeCharacteristicUUID
* @param bytes
* @param segmentation Whether to subcontract the send,true will packet the send with up to 20 bytes
* @param immediately Whether to send it immediately or not (it needs to be optimized for the queue mechanism of the command, such as: measurement termination, measurement of the heart rate of the bracelet, etc.)
*/
void broadcastWriteBle(Context context, String notifyServiceUUID,
String notifyCharacteristicUUID, String writeServiceUUID,
String writeCharacteristicUUID, byte[] bytes, boolean segmentation,
boolean immediately)
/**
* Whether bluetooth is available
* @return
*/
boolean bleIsEnabled()
/**
* Verify or enable bluetooth
*
* @param activity
* @param resultCode
* @return
*/
boolean validOrOpenBle(Activity activity, int resultCode)
/**
* Start scan
*
* @param context
*/
void startScan(final Context context)
/**
* Start scan
* @param context
* @param scanFilterName Filter name
*/
void startScan(final Context context, final S
没有合适的资源?快使用搜索试试~ 我知道了~
资源详情
资源评论
资源推荐
收起资源包目录
android ble lib (789个子文件)
169uM0OPf9iXLmwQWWFZYKzSqOM= 27KB
169uM0OPf9iXLmwQWWFZYKzSqOM= 27KB
40PscPWhC7ewEXpYsUGb2gbgu+c= 33KB
40PscPWhC7ewEXpYsUGb2gbgu+c= 33KB
5hqxYBBi7mD_uAKfLTNP4xXC4aM= 9KB
5hqxYBBi7mD_uAKfLTNP4xXC4aM= 9KB
6V5vnNvsUYWQwfspaziu_GKuv+I= 54KB
6V5vnNvsUYWQwfspaziu_GKuv+I= 54KB
8tCPwrxcmiQcblP+utRNVmJf02E= 33KB
8tCPwrxcmiQcblP+utRNVmJf02E= 33KB
9AhLLGwbqBkk5Wy5mvVVZaBl18U= 33KB
9AhLLGwbqBkk5Wy5mvVVZaBl18U= 33KB
9ylb1Hmm5SBbzy24p3OtucuakkY= 34KB
9ylb1Hmm5SBbzy24p3OtucuakkY= 34KB
9Zh7y_MdiMdqT6kVtj1wuH9+JEc= 11KB
9Zh7y_MdiMdqT6kVtj1wuH9+JEc= 11KB
aatj8PIoC6Aa+FLI+6YRUfdpQBQ= 118KB
aatj8PIoC6Aa+FLI+6YRUfdpQBQ= 118KB
androidResources 19KB
resources-debug.ap_ 417KB
app-debug.apk 1.44MB
gradlew.bat 2KB
executionHistory.bin 701KB
classAnalysis.bin 599KB
executionHistory.bin 192KB
sha1-checksums.bin 135KB
outputFiles.bin 89KB
fileHashes.bin 75KB
jarAnalysis.bin 66KB
md5-checksums.bin 31KB
taskHistory.bin 29KB
fileHashes.bin 21KB
resourceHashesCache.bin 18KB
graph.bin 235B
graph.bin 235B
graph.bin 235B
graph.bin 235B
desugar_graph.bin 235B
desugar_graph.bin 235B
dea903aa6d62eeccb3c18e8295912c5b.bin 9B
8497172d568e719d1f3a949c83899f43.bin 9B
94e15d2872b0d7efacdedc285d1b01f5.bin 4B
last-build.bin 1B
last-build.bin 1B
WalleBleService.class 20KB
WalleBleService.class 20KB
DeviceScanActivity.class 9KB
DeviceScanActivity.class 9KB
BleUtil.class 7KB
BleUtil.class 7KB
MainActivity.class 6KB
WalleBleService$2.class 5KB
WalleBleService$2.class 5KB
BleMessageQueue.class 5KB
BleMessageQueue.class 5KB
WalleBleService$1.class 4KB
WalleBleService$1.class 4KB
DeviceScanActivity$LeDeviceListAdapter.class 4KB
DeviceScanActivity$LeDeviceListAdapter.class 4KB
WalleBleService$BleScanCall.class 4KB
WalleBleService$BleScanCall.class 4KB
WalleBleConfig.class 3KB
WalleBleConfig.class 3KB
BleTaskMessage.class 3KB
BleTaskMessage.class 3KB
StringUtil.class 3KB
StringUtil.class 3KB
WalleBleService$3.class 3KB
WalleBleService$3.class 3KB
MainActivity$1.class 2KB
WalleBleService$6.class 2KB
WalleBleService$6.class 2KB
WalleBleService$9.class 2KB
WalleBleService$9.class 2KB
WalleBleService$5.class 2KB
WalleBleService$5.class 2KB
DeviceScanActivity$1.class 2KB
DeviceScanActivity$1.class 2KB
ToolUtil.class 2KB
ToolUtil.class 2KB
BleUtil$2.class 2KB
BleUtil$2.class 2KB
BluetoothDeviceEntity.class 2KB
BluetoothDeviceEntity.class 2KB
DeviceScanActivity$2.class 1KB
DeviceScanActivity$2.class 1KB
WalleAction.class 1KB
WalleAction.class 1KB
LogUtil.class 1KB
LogUtil.class 1KB
InternalAction.class 1KB
InternalAction.class 1KB
WalleBleService$7.class 1KB
WalleBleService$7.class 1KB
WalleBleService$4.class 1001B
WalleBleService$4.class 1001B
BleMessageQueue$1.class 998B
BleMessageQueue$1.class 998B
WalleBleService$8.class 997B
WalleBleService$8.class 997B
共 789 条
- 1
- 2
- 3
- 4
- 5
- 6
- 8
俊哥唯一
- 粉丝: 5
- 资源: 27
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论0