private void getPairBLEAndConnectBLE() {
        BluetoothAdapter defaultAdapter = BluetoothAdapter.getDefaultAdapter();

        if (defaultAdapter != null) {
            //得到已配对的设备列表
            Set<BluetoothDevice> devices = defaultAdapter.getBondedDevices();

            for (BluetoothDevice bluetoothDevice : devices) {
                boolean isConnect = false;

                try {
                    //获取当前连接的蓝牙信息
                    isConnect = (boolean) bluetoothDevice.getClass().getMethod("isConnected").invoke(bluetoothDevice);
                } catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
                    e.printStackTrace();
                }

                if (isConnect) {
                    Log.d("markTest", "device2=" + bluetoothDevice.getAddress());
                }
                Log.d("markTest", "device1=" + bluetoothDevice.getName());
            }
        }
    }

Logo

智屏生态联盟致力于大屏生态发展,利用大屏快应用技术降低开发者开发、发布大屏应用门槛

更多推荐