Communication rebuild.

This commit is contained in:
dxl
2020-04-13 18:41:20 +08:00
parent ba9e7b78b6
commit 00886d3ba8
2 changed files with 8 additions and 5 deletions
@@ -64,7 +64,8 @@ public abstract class AbsBluetoothSpp implements DriverInterface<BluetoothDevice
//避免重复添加已经绑定过的设备
if (device != null) {
if (device.getBondState() != BluetoothDevice.BOND_BONDED) {
callback.onAttach(device);
if (callback != null)
callback.onAttach(device);
}
}
break;
@@ -77,7 +78,8 @@ public abstract class AbsBluetoothSpp implements DriverInterface<BluetoothDevice
case BluetoothDevice.ACTION_ACL_DISCONNECTED:
//蓝牙断开连接广播
device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
callback.onDetach(device);
if (callback != null)
callback.onDetach(device);
break;
case BluetoothAdapter.ACTION_STATE_CHANGED:
//蓝牙状态改变广播
@@ -67,7 +67,8 @@ public class UsbSerialControl implements DriverInterface<String, UsbManager> {
//get permission success
if (init1()) {
//初始化成功则回调串口设备加入方法
mCallback.onAttach(NAME_DRIVER_USB_UART);
if (mCallback != null)
mCallback.onAttach(NAME_DRIVER_USB_UART);
} else {
//不成则打印到LOG
Log.e(LOG_TAG, "NAME_DRIVER_USB_UART: no usb permission!");
@@ -79,8 +80,8 @@ public class UsbSerialControl implements DriverInterface<String, UsbManager> {
action.equals(UsbManager.ACTION_USB_DEVICE_ATTACHED) ||
action.equals(ACTION_BROADCAST)) {
Log.d(LOG_TAG, "收到UsbSerial设备寻找的广播!");
if (mCallback != null) {
if (init1()) {
if (init1()) {
if (mCallback != null) {
//初始化成功则回调串口设备加入方法
mCallback.onAttach(NAME_DRIVER_USB_UART);
} else {