蓝牙连接,原因码= 0x000e-Android

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了蓝牙连接,原因码= 0x000e-Android相关的知识,希望对你有一定的参考价值。

我正在尝试创建一个连接/断开BLE设备的应用程序。我已经使用标准的android BT API创建了一个应用程序。这是我连接BLE设备的代码

try {
        Log.d(TAG, "Going to connect");
        BluetoothDevice device = BluetoothAdapter.getDefaultAdapter().getRemoteDevice(macaddress);
        if (device.getBondState() == BluetoothDevice.BOND_BONDED) {
            Log.d(TAG, "Device is already bonded. try connecting it");
            if (bluetoothGatt != null) {
                Log.d(TAG, "bluetoothGatt is not null. Just connect it");
                bluetoothGatt.connect();
                return;
            }
            bluetoothGatt = device.connectGatt(getApplicationContext(), false, gattCallback);
            bluetoothGatt.requestConnectionPriority(BluetoothGatt.CONNECTION_PRIORITY_HIGH);
        } else {
            Log.d(TAG, "Device is ? =====>  " + device.getBondState() + " Create bond");
            device.createBond();
        }
    }
    catch (Exception ex) {
        Log.e(TAG, ex.toString());
    }

****广播接收器****

private final BroadcastReceiver mPairingRequestRecevier = new BroadcastReceiver() {
    @Override
    public void onReceive(Context context, Intent intent) {
        Log.d(TAG, "Intent action is: " + intent.getAction());
        if (BluetoothDevice.ACTION_PAIRING_REQUEST.equals(intent.getAction())) {
            final BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
            int type = intent.getIntExtra(BluetoothDevice.EXTRA_PAIRING_VARIANT, BluetoothDevice.ERROR);


            try {
                byte[] pinbytes;
                pinbytes = ("" + 1234).getBytes("UTF-8");
                Log.d(TAG, "+_+_+_+_+_+_+_+_+Setting pin to : +_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_");
                device.setPin(pinbytes);
                abortBroadcast();
            } catch (Exception ex) {
                ex.printStackTrace();
            }

        } else if (BluetoothDevice.ACTION_ACL_CONNECTED.equals(intent.getAction())) {
            runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    Toast.makeText(MainActivity.this, "BT Connected",Toast.LENGTH_SHORT).show();
                }
            });
            Log.d(TAG, "Device is connected");
        } else if (BluetoothDevice.ACTION_ACL_DISCONNECTED.equals(intent.getAction())) {
            runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    Toast.makeText(MainActivity.this, "BT DisConnected",Toast.LENGTH_SHORT).show();
                }
            });
            Log.d(TAG, "Device is Disconnected");
        } else if (BluetoothDevice.ACTION_BOND_STATE_CHANGED.equals(intent.getAction())) {
            int state = intent.getIntExtra(BluetoothDevice.EXTRA_BOND_STATE, -1);
            switch (state) {
                case BluetoothDevice.BOND_NONE:
                    Log.d(TAG, "The remote device is not bonded.");
                    runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            Toast.makeText(MainActivity.this, "The remote device is not bonded",Toast.LENGTH_SHORT).show();
                        }
                    });
                    break;
                case BluetoothDevice.BOND_BONDING:
                    Log.d(TAG, "Bonding is in progress with the remote device.");
                    break;
                case BluetoothDevice.BOND_BONDED:
                    Log.d(TAG, "The remote device is bonded.");
                    runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            Toast.makeText(MainActivity.this, "The remote device is bonded.",Toast.LENGTH_SHORT).show();
                        }
                    });
                    BluetoothDevice device = BluetoothAdapter.getDefaultAdapter().getRemoteDevice(macaddress);
                    bluetoothGatt = device.connectGatt(getApplicationContext(), false, gattCallback);
                    bluetoothGatt.requestConnectionPriority(BluetoothGatt.CONNECTION_PRIORITY_HIGH);
                    Log.d(TAG, "Connection done: " + bluetoothGatt);
                    break;
                default:
                    Log.d(TAG, "Unknown remote device bonding state.");
                    break;
            }
        }
    }
};

[当我尝试执行并连接设备时,它会连接,然后立即断开连接,原因码为0x000e。这是logcat的输出:

06-02 15:23:58.577 24490 24490 D MAULIK  : Going to connect
06-02 15:23:58.580  1656  1707 D BluetoothManagerService: Message: 20
06-02 15:23:58.580  1656  1707 D BluetoothManagerService: Added callback: android.bluetooth.IBluetoothManagerCallback$Stub$Proxy@d9976e7:true
06-02 15:23:58.595 24490 24490 D MAULIK  : Device is ? =====>  10 Create bond
06-02 15:23:58.595 24490 24490 I BluetoothDevice: createBond() for device 4C:55:CC:1C:8C:F6 called by pid: 24490 tid: 24490
06-02 15:23:58.597 23899 23917 D A2dpService: getA2DPService(): returning com.android.bluetooth.a2dp.A2dpService@9811aea
06-02 15:23:58.599 23899 23928 I BluetoothBondStateMachine: Bond address is:4C:55:CC:1C:8C:F6
06-02 15:23:58.599 23899 23928 D bt_btif_config: btif_get_device_type: Device [4c:55:cc:1c:8c:f6] type 2
06-02 15:23:58.599 23899 23928 I bt_btif_dm: get_cod remote_cod = 0x00001f00
06-02 15:23:58.599 23899 23928 I BluetoothBondStateMachine: Entering PendingCommandState State
06-02 15:23:58.599 23899 23927 I bt_btif_dm: get_cod remote_cod = 0x00001f00
06-02 15:23:58.599 23899 23927 D bt_btif_config: btif_get_device_type: Device [4c:55:cc:1c:8c:f6] type 2
06-02 15:23:58.600 23899 23927 I bt_btif_dm: get_cod remote_cod = 0x00001f00
06-02 15:23:58.600 23899 23927 I BluetoothBondStateMachine: bondStateChangeCallback: Status: 0 Address: 4C:55:CC:1C:8C:F6 newState: 1
06-02 15:23:58.602 23899 23942 W bt_l2cap: l2cble_init_direct_conn
06-02 15:23:58.604 23899 23928 I BluetoothBondStateMachine: Bond State Change Intent:4C:55:CC:1C:8C:F6 OldState: 10 NewState: 11
06-02 15:23:58.607 24490 24490 D MAULIK  : Intent action is: android.bluetooth.device.action.BOND_STATE_CHANGED
06-02 15:23:58.607 24490 24490 D MAULIK  : Bonding is in progress with the remote device.
06-02 15:23:58.611 23935 23939 I WCNSS_FILTER: ibs_bt_device_wakeup: Writing IBS_WAKE_IND
06-02 15:23:58.621 23899 23942 E bt_btif : bte_scan_filt_param_cfg_evt, 23
06-02 15:23:58.625 23899 23899 V BluetoothFtpService: Ftp Service onStartCommand
06-02 15:23:58.625 23899 23899 V BluetoothFtpService: PARSE INTENT action: android.bluetooth.device.action.BOND_STATE_CHANGED
06-02 15:23:58.628 23899 23899 D A2dpService: getA2DPService(): returning com.android.bluetooth.a2dp.A2dpService@9811aea
06-02 15:23:58.628 23899 23899 D BluetoothFtpService: device: DB9-8CF6
06-02 15:23:58.633 23899 23899 D BluetoothDunService: parseIntent: action: android.bluetooth.device.action.BOND_STATE_CHANGED
06-02 15:23:58.637 23899 23899 D A2dpService: getA2DPService(): returning com.android.bluetooth.a2dp.A2dpService@9811aea
06-02 15:23:58.637 23899 23899 D BluetoothDunService: device: DB9-8CF6
06-02 15:23:58.646 23899 23942 I bt_btm_ble: btm_ble_resolve_random_addr_on_conn_cmpl unable to match and resolve random address
06-02 15:23:58.646 23899 23942 W bt_btm  : btm_acl_created hci_handle=5 link_role=0  transport=2
06-02 15:23:58.755 23899 23942 E bt_btm  : BTM_SetBlePhy failed, peer does not support request
06-02 15:23:58.760 23899 23927 D BtGatt.GattService: onConnected() connId=5, address=4C:55:CC:1C:8C:F6, connected=true
06-02 15:23:58.761 23899 23942 W bt_smp  : io_cap = 4
06-02 15:23:58.761 23899 23927 D BluetoothGattServer: onServerConnectionState() - status=0 serverIf=5 device=4C:55:CC:1C:8C:F6
06-02 15:23:58.762 23899 23942 W bt_smp  : rcvd auth_req: 0x2d, io_cap: 4                         loc_oob_flag: 0 loc_enc_size: 16,local_i_key: 0x0f, local_r_key: 0x0f
06-02 15:23:58.762 23899 23942 W bt_smp  : lmp_version_below LMP version 7 < 8
06-02 15:23:58.762 23899 23942 W bt_smp  : set auth_req: 0x2d, local_i_key: 0x07, local_r_key: 0x07
06-02 15:23:58.765 23899 23942 W bt_smp  : smp_br_connect_callback is called on unexpected transport 2
06-02 15:23:58.765 23899 23942 W bt_btm  : btm_read_remote_version_complete: BDA: 4c-55-cc-1c-8c-f6
06-02 15:23:58.765 23899 23942 W bt_btm  : btm_read_remote_version_complete lmp_version 7 manufacturer 15 lmp_subversion 8719
06-02 15:23:58.766 23899 23942 E bt_btif : bta_dm_acl_change new acl connetion:count = 1
06-02 15:23:58.766 23899 23942 W bt_btif : bta_dm_acl_change info: 0x0
06-02 15:23:58.766 23899 23942 W bt_l2cap: L2CA_SetDesireRole() new:x1, disallow_switch:0
06-02 15:23:58.769 23899 23927 D bt_btif_dm: remote version info [4c:55:cc:1c:8c:f6]: 0, 0, 0
06-02 15:23:58.773 23899 23927 E BluetoothRemoteDevices: state12newState0
06-02 15:23:58.773 23899 23927 D BluetoothRemoteDevices: aclStateChangeCallback: State:Connected to Device:4C:55:CC:1C:8C:F6
06-02 15:23:58.782 24490 24490 D MAULIK  : Intent action is: android.bluetooth.device.action.ACL_CONNECTED
06-02 15:23:58.794 24490 24490 D MAULIK  : Device is connected
06-02 15:23:58.892 23899 23942 W bt_l2cap: l2cble_process_conn_update_evt: Error status: 14
06-02 15:23:58.895 23899 23942 W bt_btif : bta_gattc_conn_cback() - cif=3 connected=0 conn_id=3 reason=0x000e
06-02 15:23:58.896 23899 23942 W bt_btif : bta_gattc_conn_cback() - cif=4 connected=0 conn_id=4 reason=0x000e
06-02 15:23:58.896 23899 23942 W bt_btif : bta_gattc_conn_cback() - cif=6 connected=0 conn_id=6 reason=0x000e
06-02 15:23:58.898 23899 23927 D BtGatt.GattService: onConnected() connId=5, address=4C:55:CC:1C:8C:F6, connected=false
06-02 15:23:58.898 23899 23927 D BluetoothGattServer: onServerConnectionState() - status=0 serverIf=5 device=4C:55:CC:1C:8C:F6
06-02 15:23:58.898 23899 23942 W bt_l2cap: L2CA_RemoveFixedChnl()  CID: 0x0006  BDA: 4c55cc1c8cf6 not connected
06-02 15:23:58.900 23899 23927 D bt_btif_config: btif_get_device_type: Device [4c:55:cc:1c:8c:f6] type 2
06-02 15:23:58.901 23899 23942 I bt_btm_sec: btm_sec_disconnected clearing pending flag handle:5 reason:14
06-02 15:23:58.906 23899 23942 W bt_l2cap: L2CA_SetDesireRole() new:x1, disallow_switch:0
06-02 15:23:58.906 23899 23942 E bt_btif : bta_gattc_mark_bg_conn unable to find the bg connection mask for: 4c:55:cc:1c:8c:f6
06-02 15:23:58.907 23899 23927 I bt_btif_dm: get_cod remote_cod = 0x00001f00
06-02 15:23:58.908 23899 23927 I BluetoothBondStateMachine: bondStateChangeCallback: Status: 9 Address: 4C:55:CC:1C:8C:F6 newState: 0
06-02 15:23:58.909 23899 23928 D BluetoothAdapterProperties: Failed to remove device: 4C:55:CC:1C:8C:F6
06-02 15:23:58.914 23899 23928 I BluetoothBondStateMachine: Bond State Change Intent:4C:55:CC:1C:8C:F6 OldState: 11 NewState: 10
06-02 15:23:58.914 23899 23927 E BluetoothRemoteDevices: state12newState1
06-02 15:23:58.914 23899 23927 D BluetoothRemoteDevices: aclStateChangeCallback: State:DisConnected to Device:4C:55:CC:1C:8C:F6
06-02 15:23:58.916 24490 24490 D MAULIK  : Intent action is: android.bluetooth.device.action.BOND_STATE_CHANGED
06-02 15:23:58.916 24490 24490 D MAULIK  : The remote device is not bonded.
06-02 15:23:58.930 23899 23899 D AvrcpBipRsp: onReceive: android.bluetooth.device.action.ACL_DISCONNECTED
06-02 15:23:58.931 23899 23899 D BluetoothMapService: onReceive
06-02 15:23:58.931 23899 23899 D BluetoothMapService: onReceive: android.bluetooth.device.action.ACL_DISCONNECTED
06-02 15:23:58.931 23899 23899 E BluetoothMapService: Unexpected error!
06-02 15:23:58.935 23899 23928 D A2dpService: getA2DPService(): returning com.android.bluetooth.a2dp.A2dpService@9811aea
06-02 15:23:58.936 24490 24490 D MAULIK  : Intent action is: android.bluetooth.device.action.ACL_DISCONNECTED
06-02 15:23:58.949 23899 23899 V BluetoothFtpService: Ftp Service onStartCommand
06-02 15:23:58.949 23899 23899 V BluetoothFtpService: PARSE INTENT action: android.bluetooth.device.action.BOND_STATE_CHANGED
06-02 15:23:58.952 24490 24490 D MAULIK  : Device is Disconnected
06-02 15:23:58.954 23899 23899 D A2dpService: getA2DPService(): returning com.android.bluetooth.a2dp.A2dpService@9811aea
06-02 15:23:58.954 23899 23899 D BluetoothFtpService: device: DB9-8CF6
06-02 15:23:58.959 23899 23928 I BluetoothBondStateMachine: StableState(): Entering Off State
06-02 15:23:58.967 23899 23899 D A2dpService: getA2DPService(): returning com.android.bluetooth.a2dp.A2dpService@9811aea
06-02 15:23:58.970 23899 23899 D BluetoothFtpService: BOND_STATE_CHANGED REFRESH trustDevices DB9-8CF6
06-02 15:23:58.975 23899 23899 D BluetoothDunService: parseIntent: action: android.bluetooth.device.action.BOND_STATE_CHANGED
06-02 15:23:58.983 23899 23899 D A2dpService: getA2DPService(): returning com.android.bluetooth.a2dp.A2dpService@9811aea
06-02 15:23:58.984 23899 23899 D BluetoothDunService: device: DB9-8CF6
06-02 15:23:58.986 23899 23899 D A2dpService: getA2DPService(): returning com.android.bluetooth.a2dp.A2dpService@9811aea
06-02 15:23:58.987 23899 23899 D BluetoothDunService: BOND_STATE_CHANGED REFRESH trustDevices DB9-8CF6
06-02 15:23:58.990 23899 23899 D BluetoothPbapReceiver: PbapReceiver onReceive action = android.bluetooth.device.action.ACL_DISCONNECTED
06-02 15:23:58.991 23899 23899 D BluetoothPbapReceiver: Calling start service with action = null
06-02 15:23:58.994 23899 23899 I BluetoothPbapReceiver: Exit - onReceive for intent:android.bluetooth.device.action.ACL_DISCONNECTED
06-02 15:23:58.994 23899 23899 D BluetoothPbapService: Enter - onStartCommand for service PBAP
06-02 15:23:58.994 23899 23899 D BluetoothPbapService: action: android.bluetooth.device.action.ACL_DISCONNECTED
06-02 15:23:58.994 23899 23899 D BluetoothPbapService: Exit - onStartCommand for service PBAP
06-02 15:23:59.003 23899 23951 D A2dpService: getA2DPService(): returning com.android.bluetooth.a2dp.A2dpService@9811aea
06-02 15:23:59.004 24046 24046 I BTLEASH : BTReceive action : android.bluetooth.device.action.ACL_DISCONNECTED :: Device : DB9-8CF6
06-02 15:23:59.006 23899 23961 D A2dpService: getA2DPService(): returning com.android.bluetooth.a2dp.A2dpService@9811aea
06-02 15:23:59.015 23899 23899 V BluetoothFtpService: Ftp Service onStartCommand
06-02 15:23:59.015 23899 23899 V BluetoothFtpService: PARSE INTENT action: android.bluetooth.device.action.ACL_DISCONNECTED
06-02 15:23:59.026 23899 23899 D BluetoothDunService: parseIntent: action: android.bluetooth.device.action.ACL_DISCONNECTED
06-02 15:23:59.905 23935 23945 I WCNSS_FILTER: ibs_wcnss_bt_device_sleep: TX Awake, Sending SLEEP_IND

[当我检查原因码0x000e时,它说这是因为BT_HCI_OP_PIN_CODE_NEG_REPLY。但是我不知道为什么会出现原因代码?

提前感谢!

Maulik

答案

我找到了上述问题的解决方案。

问题是我称他为“ createBond”方法,因为我希望将其配对。但是我没有配对的设备只是简单地连接而不配对,所以我删除了配对代码,直接调用了gatt.connect()方法。

谢谢

以上是关于蓝牙连接,原因码= 0x000e-Android的主要内容,如果未能解决你的问题,请参考以下文章

BLE蓝牙断开连接原因对照表

手机蓝牙与手机蓝牙连接时不弹出配对码对话框

连接无线打印机总操作失败,错误为0x0000046a,是啥原因呢?

苹果5蓝牙耳机怎么用

树莓派3代B版和蓝牙BLE命令通讯

Android怎么检测蓝牙的连接状态?如果一段断开,我这边怎么检测得到?