android监听蓝牙连接状态

 IntentFilter intentFilter = new IntentFilter();
        intentFilter.addAction(BluetoothAdapter.ACTION_STATE_CHANGED);
        intentFilter.addAction(BluetoothDevice.ACTION_ACL_DISCONNECTED);
        intentFilter.addAction(BluetoothDevice.ACTION_ACL_CONNECTED);
        VrHelp.getContext().registerReceiver(new BroadcastReceiver() {
            @Override
            public void onReceive(Context context, Intent intent) {
                Log.d(TAG, "registerBtConnect action : " + intent.getAction());
                switch (intent.getAction()){
                    case BluetoothDevice.ACTION_ACL_CONNECTED:
                        isConnectBtDevices = true;
                        Log.d(TAG, "notify TXZ bt connect :" + VrBtManager.getInstance().notifyBtConnectState(true));
                        break;
                    case BluetoothDevice.ACTION_ACL_DISCONNECTED:
                        isConnectBtDevices = false;
                        Log.d(TAG, "notify TXZ bt disconnect :" + VrBtManager.getInstance().notifyBtConnectState(false));
                        break;
                    default:
                        break;
                }
            }
        },intentFilter);

你可能感兴趣的:(android)