Android 应用程序的蓝牙连接自动断开

2024-03-11

我正在创建一个应用程序,它以编程方式与 Android 应用程序连接 BLE 设备。这是我的连接/断开连接代码

当用户单击“连接”按钮时

new Thread(new Runnable() {
            @Override
            public void run() {
                mConnecting = true;
                mConnectException = null;
                mConnectWait.close(); // Reset the condition.
                if (mConnectedGatt != null) {
                    // Reconnect to the BLE DEX adapter.
                    Logger.d(LOG_TAG, "going to connect");
                    mConnectedGatt.connect();
                    BluetoothDevice device = mBluetoothAdapter.getRemoteDevice(deviceAddress);
                    device.connectGatt(mContext, false, mGattCallback);
                } else {
                    // Start scanning BLE devices.
                    Logger.d(LOG_TAG, "going to scan LE Devices");
                    scanLeDevice(true);
                }
                mConnectWait.block(); // Wait for connect to complete
                try {
                    if (mConnected) {
                        connectCallback.onConnectSuccess();

                    } else { // Error occurred in the connecting process
                        if (null == mConnectException) {
                            mConnectException = new BleDexException(
                                    "Failed to connect to the BLE DEX adapter",
                                    BleDexException.ERROR_BLE_CONNECT_FAILED);
                        }
                        connectCallback.onConnectFailed(mConnectException);
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }

                mConnecting = false;
            }
        }).start();

扫码:

if (!mBleScanning) {
            // Stops scanning after a pre-defined scan period.
            mHandler.postDelayed(new Runnable() {
                @Override
                public void run() {
                    mBleScanning = false;
                    if ((null != mBleScanner) && (mBluetoothAdapter.getState() == BluetoothAdapter.STATE_ON)) {
                        mBleScanner.stopScan(mScanCallback);
                        if (mConnecting) {
                            Logger.e(LOG_TAG, "Timed out in scanning BLE devices");
                            mConnectException = new BleDexException(
                                    "Timed out in scanning BLE devices",
                                    BleDexException.ERROR_BLE_CONNECT_FAILED);
                            mConnectWait.open();
                        }
                    }
                }
            }, mBleScanPeriod);

            mBleScanning = true;
            //ScanFilter scanFilter = new ScanFilter.Builder().setServiceUuid(new ParcelUuid(DEX_SERVICE_SPP)).build();
            ScanFilter scanFilter = new ScanFilter.Builder().setDeviceName("DEXAdapter").build();
            java.util.ArrayList<ScanFilter> scanFilterList = new java.util.ArrayList<ScanFilter>();
            scanFilterList.add(scanFilter);
            ScanSettings scanSettings = new ScanSettings.Builder()
                    .setScanMode(ScanSettings.SCAN_MODE_BALANCED)
                    .build();
            if((null != mBleScanner) && (mBluetoothAdapter.getState() == BluetoothAdapter.STATE_ON))
                mBleScanner.startScan(scanFilterList, scanSettings, mScanCallback);
        }
    } else {
        Logger.d(LOG_TAG, "stop scanning. what 's the scan flag is: " + mBleScanning);
        if (mBleScanning) {
            mBleScanning = false;
            if ((null != mBleScanner) && (mBluetoothAdapter.getState() == BluetoothAdapter.STATE_ON))
                mBleScanner.stopScan(mScanCallback);
        }
    }

这是配对意图的广播接收器

public void onReceive(Context context, Intent intent) {
        String action = intent.getAction();
        if (BluetoothDevice.ACTION_PAIRING_REQUEST.equals(action)) {
            if (mBtPin == null || mBtMacAddress == null) {
                return;
            }
            // Programmatically set the Bluetooth PIN.
            device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
            pairingRequestType = intent.getIntExtra(BluetoothDevice.EXTRA_PAIRING_VARIANT,
                    BluetoothDevice.ERROR);
            Logger.d(LOG_TAG, "Received pairing request intent, Device mac address is: " + mBtMacAddress +
                    ". Device pairingrequest type is: " + pairingRequestType);
            if (device.getAddress().equals(mBtMacAddress)) {
                try {
                    int btpin = Integer.parseInt(mBtPin);
                    Logger.d(LOG_TAG, "Set pin to BT = " + btpin);
                    byte[] pinbytes;
                    pinbytes = ("" + btpin).getBytes("UTF-8");
                    device.setPin(pinbytes);
                    abortBroadcast();
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        } else if (BluetoothDevice.ACTION_BOND_STATE_CHANGED.equals(action)) {
            int state = intent.getIntExtra(BluetoothDevice.EXTRA_BOND_STATE, -1);
            switch (state) {
                case BluetoothDevice.BOND_NONE:
                    Logger.d(LOG_TAG, "Remote device is not bonded. Device: ");
                case BluetoothDevice.BOND_BONDING:
                    Logger.d(LOG_TAG, "Remote device is in bonding process");
                    break;
                case BluetoothDevice.BOND_BONDED:
                    Logger.d(LOG_TAG, "Remote device is paired");
                    BluetoothDevice bluetoothDevice = mBluetoothAdapter.getRemoteDevice(deviceAddress);
                    mConnectedGatt = bluetoothDevice.connectGatt(mContext, false, mGattCallback);
                    if (mConnectedGatt == null) {
                        Logger.e(LOG_TAG, "Failed to connect to GATT server");
                        if (mConnecting) {
                            mConnectException = new BleDexException(
                                    "Failed to connect to GATT server",
                                    BleDexException.ERROR_BLE_CONNECT_FAILED);
                            mConnectWait.open();
                        }
                    }
                    //scanLeDevice(false);
                    break;
            }
        }
    }
};

发生的情况是,一旦我按下连接按钮,它就会检查设备是否已连接?如果没有,它将开始蓝牙 LE 扫描。我添加了 ScanFilter 来扫描设备,以便它扫描有限的设备。

一旦应用程序收到扫描回调,它就会使用 createbond() 方法对设备进行配对。一旦完成并配对完成,它将尝试连接蓝牙 Gatt。

所有这些在第一次尝试时就成功了。但一段时间后,应用程序会自动断开蓝牙设备。

这是自动断线的日志

07-05 15:15:26.101  6698  6698 D BleDexToolkitSample: Invoice send transaction initiated and is in progress.
07-05 15:15:26.103  6698  6765 D BleDexToolkitSample: SetConfigTransmissionControlNumber Success
07-05 15:15:26.103  6698  6765 D BleDexToolkitSample: SetConfigTestIndicator Success
07-05 15:15:26.103  6698  6765 D BleDexToolkitSample: SetRetailer Success
07-05 15:15:26.104  6698  6765 D BleDexToolkitSample: SetSupplier Success
07-05 15:15:26.112  6698  6765 D BleDexToolkitSample: BeginTransactionSet Success
07-05 15:15:26.115  6698  6765 D BleDexToolkitSample: WriteSTSegment Success
07-05 15:15:26.116  6698  6765 D BleDexToolkitSample: WriteG82Segment Success
07-05 15:15:26.116  6698  6765 D BleDexToolkitSample: WriteLoopStart Success
07-05 15:15:26.117  6698  6765 D BleDexToolkitSample: WriteG83Segment Success
07-05 15:15:26.117  6698  6765 D BleDexToolkitSample: WriteG83Segment Success
07-05 15:15:26.118  6698  6765 D BleDexToolkitSample: WriteG22Segment Success
07-05 15:15:26.118  6698  6765 D BleDexToolkitSample: WriteLoopEnd Success
07-05 15:15:26.118  6698  6765 D BleDexToolkitSample: WriteG84Segment Success
07-05 15:15:26.118  6698  6765 D BleDexToolkitSample: WriteG86Segment Success
07-05 15:15:26.118  6698  6765 D BleDexToolkitSample: WriteG85Segment Success
07-05 15:15:26.119  6698  6765 D BleDexToolkitSample: WriteSESegment Success
07-05 15:15:26.119  6698  6765 D BleDexToolkitSample: EndTransactionSet Success
07-05 15:15:26.136  6698  6723 D BleDexDevice: Initiated sending data: 05 
07-05 15:15:27.168  6698  6723 D BleDexDevice: Initiated sending data: 05 
07-05 15:15:28.174  1934  2382 W bt_btif : bta_gattc_conn_cback() - cif=3 connected=0 conn_id=3 reason=0x0008
07-05 15:15:28.175  1934  2382 W bt_btif : bta_gattc_conn_cback() - cif=4 connected=0 conn_id=4 reason=0x0008
07-05 15:15:28.175  1934  2382 W bt_btif : bta_gattc_conn_cback() - cif=6 connected=0 conn_id=6 reason=0x0008
07-05 15:15:28.176  1934  2049 D BtGatt.GattService: onConnected() connId=5, address=00:10:20:8E:26:97, connected=false
07-05 15:15:28.176  1934  2382 W bt_btif : bta_gattc_conn_cback() - cif=8 connected=0 conn_id=8 reason=0x0008
07-05 15:15:28.176  1934  2049 D BluetoothGattServer: onServerConnectionState() - status=0 serverIf=5 device=00:10:20:8E:26:97
07-05 15:15:28.180  1934  2049 D BtGatt.GattService: onDisconnected() - clientIf=8, connId=8, address=00:10:20:8E:26:97
07-05 15:15:28.181  6698  6711 D BluetoothGatt: onClientConnectionState() - status=8 clientIf=8 device=00:10:20:8E:26:97
07-05 15:15:28.181  6698  6711 E BleDexDevice: onConnectionStateChange failure status=8 newState=0
07-05 15:15:28.183  1934  2049 E BluetoothRemoteDevices: state12newState1
07-05 15:15:28.183  1934  2049 D BluetoothRemoteDevices: aclStateChangeCallback: State:DisConnected to Device:00:10:20:8E:26:97
07-05 15:15:28.189  6698  6698 D BleDexToolkitSample: BLE DEX Adapter disconnected.
07-05 15:15:28.193  1934  1934 D AvrcpBipRsp: onReceive: android.bluetooth.device.action.ACL_DISCONNECTED
07-05 15:15:28.193  1934  1934 D BluetoothMapService: onReceive
07-05 15:15:28.193  1934  1934 D BluetoothMapService: onReceive: android.bluetooth.device.action.ACL_DISCONNECTED
07-05 15:15:28.194  1934  1934 E BluetoothMapService: Unexpected error!
07-05 15:15:28.194  1934  1934 D BluetoothPbapReceiver: PbapReceiver onReceive action = android.bluetooth.device.action.ACL_DISCONNECTED
07-05 15:15:28.195  1934  1934 D BluetoothPbapReceiver: Calling start service with action = null
07-05 15:15:28.199  1934  1934 I BluetoothPbapReceiver: Exit - onReceive for intent:android.bluetooth.device.action.ACL_DISCONNECTED
07-05 15:15:28.199  1934  1934 D BluetoothPbapService: Enter - onStartCommand for service PBAP
07-05 15:15:28.200  1934  1934 D BluetoothPbapService: action: android.bluetooth.device.action.ACL_DISCONNECTED
07-05 15:15:28.200  1934  1934 D BluetoothPbapService: Exit - onStartCommand for service PBAP
07-05 15:15:28.203  1934  1952 E BtGatt.GattService: writeCharacteristic() - No connection for 00:10:20:8E:26:97...
07-05 15:15:28.203  6698  6723 D BleDexDevice: Initiated sending data: 05 
07-05 15:15:28.219  1934  4912 D A2dpService: getA2DPService(): returning com.android.bluetooth.a2dp.A2dpService@b82a9b1
07-05 15:15:28.219  4939  4939 I BTLEASH : BTReceive action : android.bluetooth.device.action.ACL_DISCONNECTED :: Device : DEXAdapter
07-05 15:15:28.233  1934  1934 V BluetoothFtpService: PARSE INTENT action: android.bluetooth.device.action.ACL_DISCONNECTED
07-05 15:15:28.239  1934  1934 D BluetoothDunService: parseIntent: action: android.bluetooth.device.action.ACL_DISCONNECTED

现在我稍微改变了应用程序的行为,而不是配对和连接设备,而是直接连接设备而不进行配对。通过此更改,我看到蓝牙连接在连接 30 秒后自动断开。以下是日志:

=Bluetooth Connected successfully logs =
07-10 13:27:00.554  5001  5001 D BleDexToolkitSample: Connecting to BLE DEX Adapter.
07-10 13:27:00.556  5001  5338 D BleDexDevice: device found, device address is: 00:10:20:8E:26:97
07-10 13:27:00.557  5001  5338 D BluetoothGatt: connect() - device: 00:10:20:8E:26:97, auto: false
07-10 13:27:00.558  5001  5338 D BluetoothGatt: registerApp()
07-10 13:27:00.558  5001  5338 D BluetoothGatt: registerApp() - UUID=9ed830a0-85b0-4192-9b4d-c9960f5bca84
07-10 13:27:00.560  1957  2829 D BtGatt.GattService: registerClient() - UUID=9ed830a0-85b0-4192-9b4d-c9960f5bca84
07-10 13:27:00.562  1957  2068 D BtGatt.GattService: onClientRegistered() - UUID=9ed830a0-85b0-4192-9b4d-c9960f5bca84, clientIf=9
07-10 13:27:00.562  5001  5015 D BluetoothGatt: onClientRegistered() - status=0 clientIf=9
07-10 13:27:00.563  1957  5052 D A2dpService: getA2DPService(): returning com.android.bluetooth.a2dp.A2dpService@d4dde01
07-10 13:27:00.564  1957  5052 I A2dpService: audio isMusicActive is false
07-10 13:27:00.565  1957  5052 D BtGatt.GattService: clientConnect() - address=00:10:20:8E:26:97, isDirect=true
07-10 13:27:00.565  1957  2068 D bt_btif_config: btif_get_address_type: Device [00:10:20:8e:26:97] address type 0
07-10 13:27:00.566  1957  2068 D bt_btif_config: btif_get_device_type: Device [00:10:20:8e:26:97] type 2
07-10 13:27:00.567  1957  2319 W bt_l2cap: l2cble_init_direct_conn
07-10 13:27:00.573  2198  2304 I WCNSS_FILTER: ibs_bt_device_wakeup: Writing IBS_WAKE_IND
07-10 13:27:01.577  2198  2325 I WCNSS_FILTER: ibs_wcnss_bt_device_sleep: TX Awake, Sending SLEEP_IND
07-10 13:27:01.926  1957  2319 W bt_btm  : btm_acl_created hci_handle=4 link_role=0  transport=2
07-10 13:27:01.927  2198  2304 I WCNSS_FILTER: ibs_bt_device_wakeup: Writing IBS_WAKE_IND
07-10 13:27:01.946  1957  2068 D BtGatt.GattService: onConnected() connId=5, address=00:10:20:8E:26:97, connected=true
07-10 13:27:01.946  1957  2068 D BluetoothGattServer: onServerConnectionState() - status=0 serverIf=5 device=00:10:20:8E:26:97
07-10 13:27:01.946  1957  2319 W bt_smp  : smp_br_connect_callback is called on unexpected transport 2
07-10 13:27:01.948  1957  2068 D bt_btif_config: btif_get_device_type: Device [00:10:20:8e:26:97] type 2
07-10 13:27:01.948  1957  2319 E bt_btif : bta_dm_acl_change new acl connetion:count = 1
07-10 13:27:01.949  1957  2319 W bt_btif : bta_dm_acl_change info: 0x0
07-10 13:27:01.949  1957  2319 W bt_l2cap: L2CA_SetDesireRole() new:x1, disallow_switch:0
07-10 13:27:01.949  1957  2068 D BluetoothRemoteDevices: Property type: 4
07-10 13:27:01.950  1957  2319 E bt_btif : bta_gattc_cache_load: can't open GATT cache file /data/misc/bluetooth/gatt_cache_0010208e2697 for reading, error: No such file or directory
07-10 13:27:01.952  1957  2068 D BluetoothRemoteDevices: Remote class is:7936
07-10 13:27:01.953  1957  2068 D BluetoothRemoteDevices: Property type: 5
07-10 13:27:01.953  1957  2068 D bt_btif_config: btif_get_device_type: Device [00:10:20:8e:26:97] type 2
07-10 13:27:01.953  1957  2068 I bt_btif_dm: get_cod remote_cod = 0x00001f00
07-10 13:27:01.953  1957  2068 I BluetoothBondStateMachine: bondStateChangeCallback: Status: 0 Address: 00:10:20:8E:26:97 newState: 1
07-10 13:27:01.954  1957  2068 I BluetoothBondStateMachine: sspRequestCallback: [B@f9753ea name: [B@ffc36db cod: 7936 pairingVariant 2 passkey: 0
07-10 13:27:01.955  1957  2068 D bt_btif_dm: remote version info [00:10:20:8e:26:97]: 0, 0, 0
07-10 13:27:01.957  1957  2068 E BluetoothRemoteDevices: state12newState0
07-10 13:27:01.957  1957  2068 D BluetoothRemoteDevices: aclStateChangeCallback: State:Connected to Device:00:10:20:8E:26:97
07-10 13:27:01.957  1957  2069 I BluetoothBondStateMachine: Bond State Change Intent:00:10:20:8E:26:97 OldState: 10 NewState: 11
07-10 13:27:01.957  1957  2069 I BluetoothBondStateMachine: Entering PendingCommandState State
07-10 13:27:01.958  2128  2128 W BluetoothEventManager: CachedBluetoothDevice for device 00:10:20:8E:26:97 not found, calling readPairedDevices().
07-10 13:27:01.961  2128  2128 E BluetoothEventManager: Got bonding state changed for 00:10:20:8E:26:97, but we have no record of that device.
07-10 13:27:01.974  1957  2068 D BtGatt.GattService: onConnected() - clientIf=9, connId=9, address=00:10:20:8E:26:97
07-10 13:27:01.975  5001  5015 D BluetoothGatt: onClientConnectionState() - status=0 clientIf=9 device=00:10:20:8E:26:97
07-10 13:27:01.975  5001  5015 D BluetoothGatt: discoverServices() - device: 00:10:20:8E:26:97
07-10 13:27:01.977  1957  2173 D BtGatt.GattService: discoverServices() - address=00:10:20:8E:26:97, connId=9
07-10 13:27:01.978  1957  1957 V BluetoothFtpService: Ftp Service onStartCommand
07-10 13:27:01.978  1957  1957 V BluetoothFtpService: PARSE INTENT action: android.bluetooth.device.action.BOND_STATE_CHANGED
07-10 13:27:01.984  5001  5001 D BleDexDevice: Received pairing request intent, Device mac address is: 00:10:20:8E:26:97. Device pairingrequest type is: 3
07-10 13:27:01.984  5001  5001 D BleDexDevice: Set pin to BT = 369371
07-10 13:27:01.986  1957  1957 D A2dpService: getA2DPService(): returning com.android.bluetooth.a2dp.A2dpService@d4dde01
07-10 13:27:01.987  1957  1957 D BluetoothFtpService: device: DEXAdapter
07-10 13:27:01.987  1957  2319 W bt_smp  : SMP_PasskeyReply() - Wrong State: 1
07-10 13:27:01.990  1957  2319 E bt_btm  : BTM_SetBlePhy failed, peer does not support request
07-10 13:27:01.993  1957  1957 D BluetoothDunService: parseIntent: action: android.bluetooth.device.action.BOND_STATE_CHANGED
07-10 13:27:02.000  1957  1957 D A2dpService: getA2DPService(): returning com.android.bluetooth.a2dp.A2dpService@d4dde01
07-10 13:27:02.002  1957  1957 D BluetoothDunService: device: DEXAdapter
07-10 13:27:02.456  1957  2319 W bt_btm  : btm_read_remote_version_complete: BDA: 00-10-20-8e-26-97
07-10 13:27:02.456  1957  2319 W bt_btm  : btm_read_remote_version_complete lmp_version 7 manufacturer 13 lmp_subversion 528
07-10 13:27:02.837  1957  2319 W bt_bta_gattc: bta_gattc_explore_srvc no more services found
07-10 13:27:02.840  1957  2068 D BtGatt.GattService: onSearchCompleted() - connId=9, status=0
07-10 13:27:02.843  1957  2068 D bt_bta_gattc: bta_gattc_get_gatt_db
07-10 13:27:02.845  1957  2068 D BtGatt.GattService: onGetGattDb() - address=00:10:20:8E:26:97
07-10 13:27:02.846  1957  2068 D BtGatt.GattService: got service with UUID=00001800-0000-1000-8000-00805f9b34fb
07-10 13:27:02.846  1957  2068 D BtGatt.GattService: got characteristic with UUID=00002a00-0000-1000-8000-00805f9b34fb
07-10 13:27:02.846  1957  2068 D BtGatt.GattService: got characteristic with UUID=00002a01-0000-1000-8000-00805f9b34fb
07-10 13:27:02.846  1957  2068 D BtGatt.GattService: got characteristic with UUID=00002a04-0000-1000-8000-00805f9b34fb
07-10 13:27:02.846  1957  2068 D BtGatt.GattService: got service with UUID=00001801-0000-1000-8000-00805f9b34fb
07-10 13:27:02.846  1957  2068 D BtGatt.GattService: got service with UUID=f000c0e0-0451-4000-b000-000000000000
07-10 13:27:02.846  1957  2068 D BtGatt.GattService: got characteristic with UUID=f000c0e1-0451-4000-b000-000000000000
07-10 13:27:02.846  1957  2068 D BtGatt.GattService: got descriptor with UUID=00002902-0000-1000-8000-00805f9b34fb
07-10 13:27:02.846  1957  2068 D BtGatt.GattService: got descriptor with UUID=00002901-0000-1000-8000-00805f9b34fb
07-10 13:27:02.847  1957  2068 D BtGatt.GattService: got characteristic with UUID=f000c0e2-0451-4000-b000-000000000000
07-10 13:27:02.847  1957  2068 D BtGatt.GattService: got descriptor with UUID=00002901-0000-1000-8000-00805f9b34fb
07-10 13:27:02.847  1957  2068 D BtGatt.GattService: got service with UUID=f000ffd0-0451-4000-b000-000000000000
07-10 13:27:02.847  1957  2068 D BtGatt.GattService: got characteristic with UUID=f000ffd1-0451-4000-b000-000000000000
07-10 13:27:02.847  1957  2068 D BtGatt.GattService: got descriptor with UUID=00002901-0000-1000-8000-00805f9b34fb
07-10 13:27:02.848  1957  2068 D BtGatt.GattService: got characteristic with UUID=f000ffd2-0451-4000-b000-000000000000
07-10 13:27:02.848  1957  2068 D BtGatt.GattService: got descriptor with UUID=00002901-0000-1000-8000-00805f9b34fb
07-10 13:27:02.848  1957  2068 D BtGatt.GattService: got characteristic with UUID=f000ffd3-0451-4000-b000-000000000000
07-10 13:27:02.848  1957  2068 D BtGatt.GattService: got descriptor with UUID=00002902-0000-1000-8000-00805f9b34fb
07-10 13:27:02.848  1957  2068 D BtGatt.GattService: got descriptor with UUID=00002901-0000-1000-8000-00805f9b34fb
07-10 13:27:02.848  1957  2068 D BtGatt.GattService: got service with UUID=0000180f-0000-1000-8000-00805f9b34fb
07-10 13:27:02.848  1957  2068 D BtGatt.GattService: got characteristic with UUID=00002a19-0000-1000-8000-00805f9b34fb
07-10 13:27:02.848  1957  2068 D BtGatt.GattService: got descriptor with UUID=00002902-0000-1000-8000-00805f9b34fb
07-10 13:27:02.848  1957  2068 D BtGatt.GattService: got descriptor with UUID=00002904-0000-1000-8000-00805f9b34fb
07-10 13:27:02.854  5001  5015 D BluetoothGatt: onSearchComplete() = Device=00:10:20:8E:26:97 Status=0
07-10 13:27:02.855  5001  5015 D BluetoothGatt: setCharacteristicNotification() - uuid: f000c0e1-0451-4000-b000-000000000000 enable: true
07-10 13:27:02.856  1957  1972 D BtGatt.GattService: registerForNotification() - address=00:10:20:8E:26:97 enable: true
07-10 13:27:02.857  1957  2068 D BtGatt.GattService: onRegisterForNotifications() - address=null, status=0, registered=1, handle=11
07-10 13:27:02.863  5001  5338 D BleDexToolkitSample: BLE DEX Adapter connection Success
07-10 13:27:02.870  5001  5001 D BleDexToolkitSample: BLE DEX Adapter connection Success.
07-10 13:27:03.863  2198  2325 I WCNSS_FILTER: ibs_wcnss_bt_device_sleep: TX Awake, Sending SLEEP_IND
07-10 13:27:07.947  2198  2304 I WCNSS_FILTER: ibs_bt_device_wakeup: Writing IBS_WAKE_IND
07-10 13:27:08.950  2198  2325 I WCNSS_FILTER: ibs_wcnss_bt_device_sleep: TX Awake, Sending SLEEP_IND

=android device disconneted the ble =

07-10 13:27:31.953  1957  2068 D bt_btif_config: btif_get_device_type: Device [00:10:20:8e:26:97] type 2
07-10 13:27:31.953  1957  2068 I bt_btif_dm: get_cod remote_cod = 0x00001f00
07-10 13:27:31.953  2172  5348 E bt_logger: Deleting old log file /data/media/0/bt_vnd_log20190710131438.txt
07-10 13:27:31.954  1957  2068 I BluetoothBondStateMachine: bondStateChangeCallback: Status: 1 Address: 00:10:20:8E:26:97 newState: 0
07-10 13:27:31.955  2172  5348 E bt_logger: Writing logs to file
07-10 13:27:31.955  1957  2069 D BluetoothAdapterProperties: Failed to remove device: 00:10:20:8E:26:97
07-10 13:27:31.962  2128  2128 W BluetoothEventManager: CachedBluetoothDevice for device 00:10:20:8E:26:97 not found, calling readPairedDevices().
07-10 13:27:31.964  1957  2069 I BluetoothBondStateMachine: Bond State Change Intent:00:10:20:8E:26:97 OldState: 11 NewState: 10
07-10 13:27:31.968  1957  2069 D A2dpService: getA2DPService(): returning com.android.bluetooth.a2dp.A2dpService@d4dde01
07-10 13:27:31.970  1957  2069 D A2dpService: Enter setPriority
07-10 13:27:31.972  1957  2069 D A2dpService: Saved priority 00:10:20:8E:26:97 = -1
07-10 13:27:31.972  1957  2069 D A2dpService: Exit setPriority
07-10 13:27:31.972  2128  2128 E BluetoothEventManager: Got bonding state changed for 00:10:20:8E:26:97, but we have no record of that device.
07-10 13:27:31.975  1957  2069 I BluetoothBondStateMachine: StableState(): Entering Off State
07-10 13:27:31.990  1957  1957 V BluetoothFtpService: Ftp Service onStartCommand
07-10 13:27:31.990  1957  1957 V BluetoothFtpService: PARSE INTENT action: android.bluetooth.device.action.BOND_STATE_CHANGED
07-10 13:27:31.994  1957  1957 D A2dpService: getA2DPService(): returning com.android.bluetooth.a2dp.A2dpService@d4dde01
07-10 13:27:31.994  1957  1957 D BluetoothFtpService: device: DEXAdapter
07-10 13:27:31.996  1957  1957 D A2dpService: getA2DPService(): returning com.android.bluetooth.a2dp.A2dpService@d4dde01
07-10 13:27:31.996  1957  1957 D BluetoothFtpService: BOND_STATE_CHANGED REFRESH trustDevices DEXAdapter
07-10 13:27:32.002  1957  1957 D BluetoothDunService: parseIntent: action: android.bluetooth.device.action.BOND_STATE_CHANGED
07-10 13:27:32.003  1957  1957 D A2dpService: getA2DPService(): returning com.android.bluetooth.a2dp.A2dpService@d4dde01
07-10 13:27:32.004  1957  1957 D BluetoothDunService: device: DEXAdapter
07-10 13:27:32.005  1957  1957 D A2dpService: getA2DPService(): returning com.android.bluetooth.a2dp.A2dpService@d4dde01
07-10 13:27:32.005  1957  1957 D BluetoothDunService: BOND_STATE_CHANGED REFRESH trustDevices DEXAdapter
07-10 13:27:32.020  1937  2199 W BluetoothEventManager: showUnbondMessage: Not displaying any message for reason: 9
07-10 13:27:32.021  2681  3699 I LicenseObserver: installLicenses - /storage/emulated/0/bt_vnd_log20190710132731.txt
07-10 13:27:34.953  1957  2066 D bt_osi_alarm: reschedule_root_alarm alarm expiration too close for posix timers, switching to guns
07-10 13:27:34.959  2198  2304 I WCNSS_FILTER: ibs_bt_device_wakeup: Writing IBS_WAKE_IND
07-10 13:27:34.994  1957  2319 W bt_btif : bta_gattc_conn_cback() - cif=3 connected=0 conn_id=3 reason=0x0016
07-10 13:27:34.994  1957  2319 W bt_btif : bta_gattc_conn_cback() - cif=4 connected=0 conn_id=4 reason=0x0016
07-10 13:27:34.995  1957  2319 W bt_btif : bta_gattc_conn_cback() - cif=6 connected=0 conn_id=6 reason=0x0016
07-10 13:27:34.995  1957  2319 W bt_btif : bta_gattc_conn_cback() - cif=7 connected=0 conn_id=7 reason=0x0016
07-10 13:27:34.995  1957  2319 W bt_btif : bta_gattc_conn_cback() - cif=8 connected=0 conn_id=8 reason=0x0016
07-10 13:27:34.995  1957  2068 D BtGatt.GattService: onConnected() connId=5, address=00:10:20:8E:26:97, connected=false
07-10 13:27:34.995  1957  2319 W bt_btif : bta_gattc_conn_cback() - cif=9 connected=0 conn_id=9 reason=0x0016
07-10 13:27:34.995  1957  2068 D BluetoothGattServer: onServerConnectionState() - status=0 serverIf=5 device=00:10:20:8E:26:97
07-10 13:27:34.996  1957  2319 I bt_btm_sec: btm_sec_disconnected clearing pending flag handle:4 reason:22
07-10 13:27:34.998  1957  2068 D BtGatt.GattService: onDisconnected() - clientIf=9, connId=9, address=00:10:20:8E:26:97
07-10 13:27:34.999  5001  5014 D BluetoothGatt: onClientConnectionState() - status=22 clientIf=9 device=00:10:20:8E:26:97
07-10 13:27:34.999  5001  5014 D BleDexDevice: onConnectionStateChange failure status=22 newState=0
07-10 13:27:34.999  2172  2172 E bt_logger: Logger Process: Invalid packet with no length field
07-10 13:27:34.999  2172  2172 E bt_logger: Error saving packet, buff = ound p_reg tcb_idx=0 gatt_if=9  conn_id=0x9�\
07-10 13:27:34.999  2172  2172 E bt_logger: Error saving packet, buff = 
07-10 13:27:35.000  1957  2319 W bt_l2cap: L2CA_SetDesireRole() new:x1, disallow_switch:0
07-10 13:27:35.001  1957  2319 E bt_btif : bta_gattc_mark_bg_conn unable to find the bg connection mask for: 00:10:20:8e:26:97
07-10 13:27:35.002  1957  2068 E BluetoothRemoteDevices: state12newState1
07-10 13:27:35.002  1957  2068 D BluetoothRemoteDevices: aclStateChangeCallback: State:DisConnected to Device:00:10:20:8E:26:97
07-10 13:27:35.004  5001  5001 D BleDexToolkitSample: BLE DEX Adapter disconnected.
07-10 13:27:35.006  1957  1957 D AvrcpBipRsp: onReceive: android.bluetooth.device.action.ACL_DISCONNECTED
07-10 13:27:35.006  1957  1957 D BluetoothMapService: onReceive
07-10 13:27:35.006  1957  1957 D BluetoothMapService: onReceive: android.bluetooth.device.action.ACL_DISCONNECTED
07-10 13:27:35.006  1957  1957 E BluetoothMapService: Unexpected error!
07-10 13:27:35.008  1957  1957 D BluetoothPbapReceiver: PbapReceiver onReceive action = android.bluetooth.device.action.ACL_DISCONNECTED
07-10 13:27:35.009  1957  1957 D BluetoothPbapReceiver: Calling start service with action = null
07-10 13:27:35.012  1957  1957 I BluetoothPbapReceiver: Exit - onReceive for intent:android.bluetooth.device.action.ACL_DISCONNECTED
07-10 13:27:35.013  1957  1957 D BluetoothPbapService: Enter - onStartCommand for service PBAP
07-10 13:27:35.013  1957  1957 D BluetoothPbapService: action: android.bluetooth.device.action.ACL_DISCONNECTED
07-10 13:27:35.013  1957  1957 D BluetoothPbapService: Exit - onStartCommand for service PBAP
07-10 13:27:35.026  1957  2829 D A2dpService: getA2DPService(): returning com.android.bluetooth.a2dp.A2dpService@d4dde01
07-10 13:27:35.027  5034  5034 I BTLEASH : BTReceive action : android.bluetooth.device.action.ACL_DISCONNECTED :: Device : DEXAdapter
07-10 13:27:35.030  1957  1970 D A2dpService: getA2DPService(): returning com.android.bluetooth.a2dp.A2dpService@d4dde01
07-10 13:27:35.045  1957  1957 V BluetoothFtpService: Ftp Service onStartCommand
07-10 13:27:35.046  1957  1957 V BluetoothFtpService: PARSE INTENT action: android.bluetooth.device.action.ACL_DISCONNECTED
07-10 13:27:35.053  1957  1957 D BluetoothDunService: parseIntent: action: android.bluetooth.device.action.ACL_DISCONNECTED
07-10 13:27:36.005  2198  2325 I WCNSS_FILTER: ibs_wcnss_bt_device_sleep: TX Awake, Sending SLEEP_IND
^C

提前致谢。


Disconnect with Reason 8 意味着连接超时,这是硬件问题(不是软件问题)。连接超时失败的唯一原因(至少我现在能想到的)是当两个设备尝试使用两个不同的绑定密钥时。然后两者都使用不同的密钥设置加密,然后因此失败。

您可以使用空气嗅探器来找出断开的原因或时间。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Android 应用程序的蓝牙连接自动断开 的相关文章

  • 带阴影的弯曲 Android 工具栏

    我需要为工具栏或卡片视图提供弯曲的底视图 我尝试过的 bg toolbar xml
  • 任务“:app:dexDebug”执行失败

    我目前正在处理我的项目 我决定将我的 Android Studio 更新到新版本 但在我导入项目后 它显示如下错误 Information Gradle tasks app assembleDebug app preBuild UP TO
  • ImageView 中的全尺寸图像

    我正在尝试在 ImageView 中绘制图像 但我希望它不缩放 并根据需要使用滚动条 我怎样才能做到这一点 现在我只有一个可绘制集作为 XML 中 ImageView 的 android src 这会自动缩放图像以适应屏幕宽度 我读到这可能
  • Android studio 在日志猫中“清除全部”,更改日志级别过滤器时日志仍然会回来

    在 LogCat 中 当我单击 全部清除 按钮时 它似乎清除了所有日志 但是 如果我更改日志级别并返回到之前的日志级别 则所有日志都会返回 例如 我正在查看 Verbose 我选择 全部清除 日志清除 我切换到 调试 我切换回 详细 现在所
  • doInBackground 运行时是否可以停止 asynctask?

    我正在 ActivityB Oncreate 中创建异步任务 在该任务中 我正在运行无限 while 循环doInBackground 当我转到上一个活动并再次回到该活动时 创建了另一个异步任务 我的问题现在是两个无限 while 循环正在
  • android 谷歌+登录定制

    我正在创建一个 Android 应用程序 现在我正在实现社交网络登录 Facebook 按钮很好 但 google 按钮的语言与 Facebook 不同 另外 它只说 登录 我想让它说 用谷歌登录 我是 android 编程的新手 看到我需
  • 无法合并 Dex - Android Studio 3.0

    当我在稳定频道中将 Android Studio 更新到 3 0 并运行该项目时 我开始收到以下错误 Error Execution failed for task app transformDexArchiveWithExternalLi
  • 如何将十六进制数组转换为 UIImage?

    有几个与使用 P25mi 动态打印图像相关的未解答问题 没有一个得到公认的答案 下面有几个链接 如何将图像转换为位图代码以便在 iPhone 中进行蓝牙打印 https stackoverflow com questions 1383828
  • 如何在照片删除后刷新 Android 的 MediaStore

    问题 如何使媒体存储刷新其已删除文件的条目 从外部存储中删除代码中的照片后 我仍然在图库中看到已删除照片的插槽 空白照片 画廊似乎反映了媒体存储 并且在媒体存储中找到了已删除的照片 直到手机重新启动或通常 直到重新扫描媒体为止 尝试扫描已删
  • 如何检测 Google Play 上是否有我的应用程序的更新? [复制]

    这个问题在这里已经有答案了 有没有办法以编程方式检查 Google Play 上我的应用程序是否有更新 以便通知用户 我知道 android google play 有自动通知 但我想使用我自己的通知 弹出消息来更新可用性 有点像 Vibe
  • 在 Android 中使用 iText 读取或打开 PDF 文件

    我是 Android 应用程序开发新手 使用 iText 我完成了 PDF 创建并在创建的文件上写入 现在我想阅读该 PDF 文件 如何使用 iText 打开或阅读 PDF 文件 例子将是可观的 那么提前 哪个是渲染 PDF 文件的最佳库
  • 如何从SurfaceView绘制到Canvas?

    我正在尝试做简单的画家 问题是Android看起来有三个独立的Canvas并给我它来顺序绘制 我用以下方式制作了用户界面SurfaceView 把霍尔德从中拿走 Override protected void onCreate Bundle
  • onTouchEvent()中如何区分移动和点击?

    在我的应用程序中 我需要处理移动和单击事件 一次点击是由一个 ACTION DOWN 操作 多个 ACTION MOVE 操作和一个 ACTION UP 操作组成的序列 理论上 如果您收到 ACTION DOWN 事件 然后收到 ACTIO
  • 如何在android中录制音频时暂停背景音乐

    我正在 Android 中开发一个音频记录应用程序 因此 如果设备音乐播放器中已播放任何背景音乐 则应在开始录制之前暂停该背景音乐 并且每当录制停止或暂停时 背景音乐都应恢复 播放录制的音频时也应该如此 有人可以帮我解决这个问题吗 提前致谢
  • 使用 hcitool 扫描低功耗蓝牙?

    当我运行此命令时 BLE 设备扫描仅持续 5 秒 sudo timeout 5s hcitool i hci0 lescan 输出显示在终端屏幕中 但是 当我将输出重定向到文件以保存广告设备的地址时 每次运行该命令时 我都会发现该文件是空的
  • 无法在 Android 模拟器中安装 apk

    我正在尝试通过 adb shell 在 ICS 模拟器中安装 apk 从一个站点下载 但出现以下错误 失败 INSTALL FAILED UID CHANGED 可能是什么问题 只需 rm r 有问题的数据目录即可 如果您在安装时遇到此错误
  • 如何更改锁屏自定义文本(所有者信息)?

    我写了程序代码 String message This is test Settings System putString context getContentResolver Settings Secure LOCK PATTERN EN
  • Amazon IAP 不会调用 onPurchaseResponse

    我有一个 Android 应用程序 它使用 IAP 我正在发送PurchasingManager initiateGetUserIdRequest 并得到用户识别成功 in onGetUserIdResponse 得到回复后Purchasi
  • Android:获取最新意图

    如何获取发送到活动的最后一个意图 的文档onNewIntent 建议我需要做这样的事情 class MyActivity public void onNewIntent Intent intent setIntent intent reac
  • 在 Android 中更新到 API 26 时,清单合并失败并出现多个错误

    我尝试使用 API 26 更新我的 gradle 安卓工作室2 3 3 但我在编译项目时遇到以下错误 这是我收到的错误的屏幕截图 应用级别build gradle Top level build file where you can add

随机推荐

  • 了解内核-前端通信——为什么我的前端冻结?

    EDIT 只需确认您是否可以重现此内容就会很有用 只需一台计算机即可尝试此操作 无需远程连接 Update似乎其他人无法在 Mac 或 Win7 上重现此问题 因此它要么是 WinXP 特定的 要么是我的机器特定的 此时我要放弃了 最好有一
  • 查找块中游标或表列的数据类型

    可以找出块内游标或变量的列的数据类型without使用系统表 虽然我知道我可以使用系统表来查找此信息 但速度会慢很多 就像是 declare my column data type varchar2 30 begin my column d
  • 如何在Windows 10下卸载Docker Machine

    我没有找到任何从 Windows 10 Edu 中删除 Docker Machine 的解决方案 但 Windows 上的 Docker Machine 文档非常少 我是 Powershell 的新手 所以也许有一个我没有找到的简单命令 g
  • oci_bind_by_name 是什么?

    what is oci bind by name http php net manual en function oci bind by name php为了 我读了 php 手册 但什么也看不懂 请有人向我解释一下 看这个例子 name
  • mongodb中_id的长度有限制吗

    背景 我已经正在接管一个应用程序 原始工程师正在离开 该应用程序充当一些相对较慢的后端服务的缓存层 因为它是 RESTful 风格的 URL 所以每个 URL 都是唯一的 应用程序使用MongoDb作为缓存的存储 并使用哈希值作为缓存 虽然
  • .pgpass 用于 Docker 化环境中的 PostgreSQL 复制

    我尝试使用 Docker 和 bash 脚本 我使用 Coreos 设置 PostgreSQL 从属服务器 我还没有找到任何方法来提供有效的 pgpass 我知道我可以创建一个 PGPASSWORD 环境变量 但出于安全原因不想这样做 如此
  • 有人可以向我指出一个使用最新路由系统的 ember.js 项目吗?如果它也使用 ember-data 则奖励积分

    我正在使用 ember js 制作我的第一个项目 到目前为止尚未找到任何使用新路由系统的示例项目 ember 文档中的所有示例都使用旧的路由 另外 如果有人知道的话 我很想看到一个使用 Ember Data 的项目示例 Thanks 您可以
  • 在 C# 中更改选项卡页时,如何将面板设置为始终位于顶部?

    我在 TabController 中有两个选项卡的程序 我还有一个我想始终放在前面的面板 不管我在哪个标签页 我尝试将面板设置为BringToFront 但是当我更改标签页时这似乎不起作用 有什么建议如何解决这个问题吗 如果面板是包含通过
  • 如何在 MySQL 中滞后列?

    考虑下表 SELECT id value FROM table ORDER BY id ASC id value 12 158 15 346 27 334 84 378 85 546 The id列自动递增但包含间隙 这value列是数字
  • CSS 嵌套 Div 具有绝对位置?

    这是一个更为复杂的案例的再现 div style width 200px background color red AS HDSKLAJD KLASJD KLASJ DKLASJDKL JASKLD JKLAS JDKLASD AS HDS
  • 如何在连接到 lein swank 的 ClojureBox (EmacsW32) REPL 中抑制 ^M 字符

    我正在从我的服务器连接到一个 swank 服务器ClojureBox http clojure billhugh com安装 IE lein swank从我的项目目录然后M x slime connect来自 EmacsW32 然而 当我这
  • 如何在方案中调试gimp的script-fu脚本?

    我尝试使用 script fu scheme 为 gimp 制作一些脚本 当然 作为一个初学者 会有很多错误和误解 现在我正在寻找一种调试这些脚本的方法 我找到了 gimp message 但结果没有显示 我不知道是否有可能将调试消息打印到
  • Magento 2:“找不到所请求的商店。请验证商店并重试。”

    每次我从英语商店视图切换到意大利语商店视图 反之亦然 时 它都会将我带到等效的主页 无论我在哪里 并抛出此错误 这是我的设置 Magento 2 3 4 全新安装 自托管 1 个网站 1 个商店 2 个商店浏览次数 对于每个商店视图一个不同
  • 闪亮的自定义输出未渲染

    我正在尝试将 D3 js 的网络可视化绑定到 Shiny 中的自定义输出 由于某种原因 我的渲染函数似乎没有被调用 这是我的代码 绑定 js var forceNetworkOB new Shiny OutputBinding forceN
  • 如何在内部java api或jest api中获取弹性搜索索引的类型名称

    我有一个名为 demo 的索引 它包含不同的类型 我在我的应用程序中使用弹性搜索 java 内部 api 和rest api 玩笑 基本上我想提出这个要求 curl XGET http localhost 9200 demo mapping
  • 如何使用 multer 存储带有文件扩展名的文件?

    设法将我的文件存储在一个文件夹中 但它们存储时没有文件扩展名 有谁知道如何存储带有文件扩展名的文件 我有一个解决方法来添加正确的文件扩展名 如果你使用path节点模块 var multer require multer var path r
  • 连接在远程 IP 上被拒绝,但在本地 IP 上被接受

    正如标题所说 我的服务器在本地计算机上运行 我对其进行了测试和调试 它运行得很好 服务器也是用java编写的 但是当我尝试用我的远程IP 而不是192 168 0 113 我使用146 255 x x 测试它时 服务器没有收到任何东西 而客
  • Kendo UI MVVM 与 TypeScript - 将 ViewModel 制作为“类”

    我正在将一个项目转换为 Typescript 它使用 Kendo UI 的 MVVM 架构 然而 我对类的概念及其与视图模型的关系有一些疑问 我将建立一个班级并扩展kendo data ObservableObject 您可以从中创建视图模
  • wget 无法下载 - 404 错误

    我尝试使用 wget 下载图像 但收到如下错误 2011 10 01 16 45 42 http www icerts com images logo jpg Resolving www icerts com 97 74 86 3 Conn
  • Android 应用程序的蓝牙连接自动断开

    我正在创建一个应用程序 它以编程方式与 Android 应用程序连接 BLE 设备 这是我的连接 断开连接代码 当用户单击 连接 按钮时 new Thread new Runnable Override public void run mC