Skip to content

Commit

Permalink
更新下载二维码
Browse files Browse the repository at this point in the history
  • Loading branch information
aicareles committed Jul 17, 2020
1 parent 8b7c669 commit 5194840
Show file tree
Hide file tree
Showing 31 changed files with 263 additions and 134 deletions.
Binary file modified .idea/caches/build_file_checksums.ser
Binary file not shown.
1 change: 0 additions & 1 deletion .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@
### 有个人项目或者定制化需求的可加QQ:823581722 进行联系
### Email:[email protected]

### 扫描下载APK:(安装密码:android)
![二维码.png](
https://android-resource.oss-cn-qingdao.aliyuncs.com/GitClub/image/mJW4.png?Expires=1577947521&OSSAccessKeyId=TMP.hhbo7QSce5gPRayo3tJUYViA69964YTNBHGVNQd8PJ6L8PVwXatiaKGcL52pcneAzwAwv8jASidyskmj3g5HypuBK8AFrBRBN7Hi8krKU8pbGWNa4fxDaHsERWtJWC.tmp&Signature=ni2nOP8Ordl5srIw9LnvBJ1I5lY%3D)
### 扫描下载APK:
![二维码.png](https://github.com/aicareles/Android-BLE/blob/master/screenshots/download.png)


# Android-BLE
Expand Down
5 changes: 2 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ buildscript {
}
}
dependencies {
// classpath 'com.android.tools.build:gradle:3.0.1'
classpath 'com.android.tools.build:gradle:3.5.3'
classpath 'com.android.tools.build:gradle:3.0.1'
// classpath 'com.android.tools.build:gradle:3.5.3'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"

// NOTE: Do not place your application dependencies here; they belong
Expand All @@ -33,7 +33,6 @@ allprojects {
repositories {
google()
jcenter()
maven { url "https://raw.githubusercontent.com/Pgyer/mvn_repo_pgyer/master" }
maven { url "https://jitpack.io" }
}
tasks.withType(Javadoc) {
Expand Down
1 change: 1 addition & 0 deletions core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ publish{
userOrg = 'superliu'//bintray.com的用户名
groupId = 'cn.com.superLei'//一个唯一值,默认包名,生成的gradle依赖前缀
artifactId = 'blelibrary'//远程仓库包名称
uploadName = 'BleLib'//bintray中包的显示名称。 如果没有设置,artifactId将用于作为包名称。
publishVersion = '3.1.0'
desc = 'Android-BLE Bluetooth framework, including scanning, connecting, enabling / disabling notifications, sending / reading data, receiving data, reading rssi, setting mtu and other Bluetooth-related operation interfaces, internally optimized connection queue, and fast write queue, And support multi-service communication, can be extended to configure Bluetooth related operations.'
website = 'https://github.com/aicareles/Android-BLE'
Expand Down
23 changes: 18 additions & 5 deletions core/src/main/java/cn/com/heaton/blelibrary/ble/Ble.java
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ public void init(Context context, Options options, InitCallback callback) {
request = (RequestListener<T>) RequestProxy.newProxy().bindProxy(context, RequestImpl.newRequestImpl());
bleRequestImpl = BleRequestImpl.getBleRequest();
bleRequestImpl.initialize(context);
initBleObserver();
BleLog.d(TAG, "Ble init success");
if (callback != null){
callback.success();
Expand All @@ -142,10 +143,8 @@ public static <T extends BleDevice> Ble<T> create(Context context, Options optio
* @param callback
*/
public void setBleStatusCallback(BleStatusCallback callback){
if (bleObserver == null) {
this.bleObserver = new BluetoothChangedObserver(context);
this.bleObserver.setBleScanCallbackInner(callback);
this.bleObserver.registerReceiver();
if (bleObserver != null) {
bleObserver.setBleScanCallbackInner(callback);
}
}

Expand Down Expand Up @@ -213,7 +212,14 @@ public void cancelConnectings(List<T> devices){
*/
public void autoConnect(T device, boolean autoConnect){
ConnectRequest<T> request = Rproxy.getRequest(ConnectRequest.class);
request.resetReConnect(device, autoConnect);
request.resetAutoConnect(device, autoConnect);
}

public void cancelAutoConnects(){
ConnectRequest<T> request = Rproxy.getRequest(ConnectRequest.class);
if(request != null){
request.cancelAutoConnect();
}
}

/**
Expand Down Expand Up @@ -474,6 +480,13 @@ private void releaseGatts() {
}
}

private void initBleObserver(){
if (bleObserver == null){
bleObserver = new BluetoothChangedObserver(context);
bleObserver.registerReceiver();
}
}

private void releaseBleObserver() {
BleLog.d(TAG, "BleObserver is released");
if (bleObserver != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,13 @@ public void run() {
bleDevice.setBleName(device.getName());
connectWrapperCallback.onConnectionChanged(bleDevice);
// We want to directly connect to the device, so we are setting the autoConnect parameter to false
BluetoothGatt bluetoothGatt = device.connectGatt(context, false, gattCallback);
BluetoothGatt bluetoothGatt;
//TODO 连接双通道蓝牙必须设置
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && device.getType() == BluetoothDevice.DEVICE_TYPE_DUAL) {
bluetoothGatt = device.connectGatt(context, false, gattCallback, BluetoothDevice.TRANSPORT_LE);
} else {
bluetoothGatt = device.connectGatt(context, false, gattCallback);
}
if (bluetoothGatt != null) {
gattHashMap.put(address, bluetoothGatt);
BleLog.d(TAG, "Trying to create a new connection.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import java.lang.ref.WeakReference;

import cn.com.heaton.blelibrary.ble.BleLog;
import cn.com.heaton.blelibrary.ble.callback.BleStatusCallback;
import cn.com.heaton.blelibrary.ble.request.ConnectRequest;
import cn.com.heaton.blelibrary.ble.request.Rproxy;
Expand Down Expand Up @@ -48,7 +49,7 @@ public void unregisterReceiver() {
}
}

class BleReceiver extends BroadcastReceiver {
static class BleReceiver extends BroadcastReceiver {
private WeakReference<BluetoothChangedObserver> mObserverWeakReference;

public BleReceiver(BluetoothChangedObserver bluetoothChangedObserver){
Expand All @@ -61,17 +62,25 @@ public void onReceive(Context context, Intent intent) {
BluetoothChangedObserver observer = mObserverWeakReference.get();
int status = intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, -1);
if (status == BluetoothAdapter.STATE_ON) {
observer.bleStatusCallback.onBluetoothStatusChanged(true);
BleLog.e("","系统蓝牙已开启");
if (observer.bleStatusCallback != null){
observer.bleStatusCallback.onBluetoothStatusChanged(true);
}
ConnectRequest request = Rproxy.getRequest(ConnectRequest.class);
request.openBluetooth();
}else if(status == BluetoothAdapter.STATE_OFF){
observer.bleStatusCallback.onBluetoothStatusChanged(false);
BleLog.e("","系统蓝牙已关闭");
if (observer.bleStatusCallback != null){
observer.bleStatusCallback.onBluetoothStatusChanged(false);
}
//如果正在扫描,则停止扫描
ScanRequest scanRequest = Rproxy.getRequest(ScanRequest.class);
if (scanRequest.isScanning()){
scanRequest.onStop();
}
//解决原生android系统,直接断开系统蓝牙不回调onConnectionStateChange接口问题
ConnectRequest request = Rproxy.getRequest(ConnectRequest.class);
request.disconnectBluetooth();
request.closeBluetooth();
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
package cn.com.heaton.blelibrary.ble.model;

import android.bluetooth.BluetoothDevice;
import android.os.Parcel;
import android.os.Parcelable;
import android.support.annotation.RestrictTo;

import java.util.HashMap;
import java.util.Map;

import cn.com.heaton.blelibrary.ble.Ble;

/**
Expand Down Expand Up @@ -35,6 +39,14 @@ public class BleDevice implements Parcelable {
/*蓝牙重命名名称(别名)*/
private String mBleAlias;

/**
* DEVICE_TYPE_UNKNOWN = 0
* DEVICE_TYPE_CLASSIC = 1
* DEVICE_TYPE_LE = 2
* DEVICE_TYPE_DUAL = 3
*/
private int mDeviceType = BluetoothDevice.DEVICE_TYPE_LE;

/*是否自动连接*/
private boolean mAutoConnect = Ble.options().autoConnect;//The default is not automatic connection

Expand All @@ -44,6 +56,11 @@ public class BleDevice implements Parcelable {
/*解析后的广播包数据*/
private ScanRecord scanRecord;

/**
* 自定义属性值
*/
private Map<String, Object> mPropertyMap;

/**
* Use the address and name of the BluetoothDevice object
* to construct the address and name of the {@code BleDevice} object
Expand All @@ -55,11 +72,14 @@ protected BleDevice(String address, String name) {

protected BleDevice(Parcel in) {
mConnectionState = in.readInt();
mDeviceType = in.readInt();
mBleAddress = in.readString();
mBleName = in.readString();
mBleAlias = in.readString();
mAutoConnect = in.readByte() != 0;
isAutoConnecting = in.readByte() != 0;
mPropertyMap = new HashMap<>();
in.readMap(mPropertyMap, getClass().getClassLoader());
}

@RestrictTo(RestrictTo.Scope.LIBRARY_GROUP)
Expand Down Expand Up @@ -143,10 +163,33 @@ public void setScanRecord(ScanRecord scanRecord) {
this.scanRecord = scanRecord;
}

public int getDeviceType() {
return mDeviceType;
}

public void setDeviceType(int deviceType) {
this.mDeviceType = deviceType;
}

public void put(String key, Object value){
if (mPropertyMap == null){
mPropertyMap = new HashMap<>();
}
mPropertyMap.put(key, value);
}

public Object get(String key){
if (mPropertyMap == null){
return null;
}
return mPropertyMap.get(key);
}

@Override
public String toString() {
return "BleDevice{" +
"mConnectionState=" + mConnectionState +
"mDeviceType=" + mDeviceType +
", mBleAddress='" + mBleAddress + '\'' +
", mBleName='" + mBleName + '\'' +
", mBleAlias='" + mBleAlias + '\'' +
Expand All @@ -162,10 +205,12 @@ public int describeContents() {
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeInt(mConnectionState);
dest.writeInt(mDeviceType);
dest.writeString(mBleAddress);
dest.writeString(mBleName);
dest.writeString(mBleAlias);
dest.writeByte((byte) (mAutoConnect ? 1 : 0));
dest.writeByte((byte) (isAutoConnecting ? 1 : 0));
dest.writeMap(mPropertyMap);
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package cn.com.heaton.blelibrary.ble.queue;

import android.support.annotation.NonNull;
import android.util.Log;

import cn.com.heaton.blelibrary.ble.BleLog;
import cn.com.heaton.blelibrary.ble.request.ConnectRequest;
import cn.com.heaton.blelibrary.ble.request.Rproxy;

Expand Down Expand Up @@ -46,6 +48,7 @@ public void remove(RequestTask requestTask) {
@Override
public void execute(RequestTask requestTask) {
connectRequest.reconnect(requestTask.getAddress());
// BleLog.i("ConnectQueue", "正在重新连接设备:>>>"+"result:"+reconnect+">>>>"+requestTask.getAddress());
}

/*@Override
Expand Down
Loading

0 comments on commit 5194840

Please sign in to comment.