Android中不稳定的可扩展连接

Android中不稳定的可扩展连接,android,bluetooth,bluetooth-lowenergy,gatt,Android,Bluetooth,Bluetooth Lowenergy,Gatt,我遵循在Android 4.3中开发蓝牙低能耗的指南 当尝试从Android手机连接到BLE设备时,有时它会在连接到BLE设备后立即断开连接 连接代码为: public void connect(final String address) { // TODO Auto-generated method stub Log.w(TAG, "BluetoothLeService Connect function."); if(mBluetoothAdap

我遵循在Android 4.3中开发蓝牙低能耗的指南

当尝试从Android手机连接到BLE设备时,有时它会在连接到BLE设备后立即断开连接

连接代码为:

public void connect(final String address) {
        // TODO Auto-generated method stub
        Log.w(TAG, "BluetoothLeService Connect function.");
        if(mBluetoothAdapter == null || address == null){
            Log.w(TAG, "BluetoothAdapter not initialized or unspecified address.");
        }

        final BluetoothDevice device = mBluetoothAdapter.getRemoteDevice(address);
        int connectState = mBluetoothManager.getConnectionState(device, BluetoothProfile.GATT);
        mBluetoothGatt = device.connectGatt(this, true, mGattCallback); 

    }
生成的日志为:

D/BluetoothGatt(13308): onClientConnectionState() - status=0 clientIf=4 device=20:73:20:00:6C:B4
I/BluetoothLeService(13308): BluetoothGattCallback-----newState = 2
I/BluetoothLeService(13308): STATE_CONNECTED:
I/Device_information(13308): BroadcastReceiver---action = ti.android.ble.common.ACTION_GATT_CONNECTED
I/BluetoothLeService(13308): ServiceDiscover
D/BluetoothGatt(13308): discoverServices() - device: 20:73:20:00:6C:B4
D/BtGatt.GattService(12125): discoverServices() - address=20:73:20:00:6C:B4, connId=4
D/BtGatt.btif(12125): btif_gattc_search_service
D/BtGatt.btif(12125): btgattc_handle_event: Event 1006
E/MP-Decision( 2172): Error setting a sleep mode for secondary cores - -38
E/BtGatt.GattService(12125): getService() - Service requested, but not available!
W/bt-l2cap(12125): L2CA_EnableUpdateBleConnParams - unknown BD_ADDR 207320006cb4
E/bt-btm  (12125): btm_sec_disconnected - Clearing Pending flag
D/BtGatt.btif(12125): btif_gattc_upstreams_evt: Event 6
D/BtGatt.GattService(12125): onSearchCompleted() - connId=4, status=129
D/BluetoothGatt(13308): onSearchComplete() = Device=20:73:20:00:6C:B4 Status=129
I/BluetoothLeService(13308): onServicesDiscovered@@@@@@-----State = 129 =
W/BluetoothLeService(13308): BluetoothLeService Connect function.
D/BluetoothManager(13308): getConnectionState()
D/BluetoothManager(13308): getConnectedDevices
D/BluetoothAdapterService(1107670808)(12125): Get Bonded Devices being called
D/BluetoothAdapterProperties(12125): getBondedDevices: length=1
D/BtGatt.GattService(12125): getDeviceType() - device=20:73:20:00:6C:B4, type=2
D/BluetoothGatt(13308): connect() - device: 20:73:20:00:6C:B4, auto: true
D/BluetoothGatt(13308): registerApp()
D/BluetoothGatt(13308): registerApp() - UUID=de8cc9a9-98e5-45d7-84f5-709bbd76e680
D/BtGatt.GattService(12125): registerClient() - UUID=de8cc9a9-98e5-45d7-84f5-709bbd76e680
D/BtGatt.btif(12125): btif_gattc_register_app
D/BtGatt.btif(12125): btif_gattc_upstreams_evt: Event 5
D/BtGatt.GattService(12125): onDisconnected() - clientIf=4, connId=4, address=20:73:20:00:6C:B4
D/BluetoothGatt(13308): onClientConnectionState() - status=133 clientIf=4 device=20:73:20:00:6C:B4
I/BluetoothLeService(13308): BluetoothGattCallback-----newState = 0
I/BluetoothLeService(13308): STATE_DISCONNECTED:
断开连接的主要原因似乎是:

E/BtGatt.GattService(12125): getService() - Service requested, but not available!
W/bt-l2cap(12125): L2CA_EnableUpdateBleConnParams - unknown BD_ADDR 207320006cb4
E/bt-btm  (12125): btm_sec_disconnected - Clearing Pending flag

有人能解释为什么会发生这种情况吗?

首先,你应该意识到这一点。你的任务是什么?你的设备似乎无法提供一些被发现的服务。这可能是设备大脑受损的原因。如果您在调用该服务后有稳定的断开连接,那么您可能根本不应该调用它